In C implementation of #colony#colang, every object has two fields, 64bit kind and 64bit value. Which means that we spend 2 64bit registers just present single value in case of primitive values such as bool, u8, u32, u64, i64, f64.
In case of GC'ed objects such as generic, array, dict, struct, union, and so on, we need indirection because these "structures" simply require more space. But in case of everything above, I think we can do better.
Perhaps, for abstract types we can move RC in "type" field, and limit mac RC count to 2 **56 which is quite large number, and currently good enough for our GC needs.
Once I wrote all of this, I think actually that this is potential premature optimization.
I need more time to experiment around this to justify such a change.
However, place where is practical benefit is with short bytes and str objects. They might fit into 128bits. We need 8bits for kind field, in case of bytes/str, since they are immutable and short, spend rest of 120bits which is 15 bytes, or 3-15 chars unicode str.
For example, long meta-programming attribute that I am aware is "__generic_get_attr__" which is 20 bytes/chars. However, if we have special form for meta-programming strings, we can assume they start and end with "__" which means that we need 16 bytes.
"__generic_get_attr__" or "generic_get_attr" is one byte above our limit, so I might need to think of shorter version such as 15 bytes "generic_getattr" or even 14 bytes "genericgetattr". User will still type "__generic_get_attr__", but it can be recognized and stiped down.
Working with these kind of strings is quite frequent and benefit could be huge.
• • •
Missing some Tweet in this thread? You can try to
force a refresh
In #colony#colang, bytes type is really not required as primitive type. str type should exist since it is unicode and mostly used by developers. However, bytes can be represented as Array<u8>.
Since #colony#colang is GC'ed using Reference Counting, refcount, or RC, we can introduce special kind of references called "immortal references" and an example is `bytes: type = Array<u8>`. This should be implementation detail and not exposed to developers.
Immortal objects are GC'ed. So, incref or decref is almost fast as NOP. It will need to check flag on object and determine if object is immortal. Immortal means it stays forever alive while programming is being executed.