Optimizing memory layouts #22
Labels
No Label
bug
core
design
errors
feature
infrastructure
optimization
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: twc/rudus#22
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I've been thinking a bunch about how to optimize a number of terms on stacks to keep things small.
We need values that are used at runtime to be as small as possible.
The current memory plan for
Value
is of paramount importance.Currently, it's 64 bytes, because
List
owns animbl::Vector
, which is 64 bytes. We can do better than this:This gets us down to 8 bytes, or 64 bits.
Some notes here:
FnDecl
, orLBox.name
) are indices toVec
s holding&'static str
s yanked from the source code. This saves us a byte over storing&'static str
s directly. This also doesn't come at a very steep cost: equality is comparing theusize
s that are stored there.Regarding NaN boxing: At current the crate I'd like to use for that, https://github.com/CraftSpider/boxing, https://craftspider.github.io/2024/09/shorts-boxing/, only implements boxing for
Box
pointers, but not forRc
--which I need. I have no idea how much faster an interpreter could be if its value type were 8 bytes instead of 16 (or 24). Or how much slower it would be if weBox
ed up ourRc
s. Or how much work it would be to extendboxing
to coverRc
s. Anyway, that's for future me to worry about.Also, we'd have to use
u32
instead ofusize
for indices, and it's probably best to useindex_vec
'sIdx
wrapper so that the index is typed. This would mean that we'd haveKeyword(KwIdx)
andInterned(StrIdx)
. Which, great!So this is from a long time ago. We're still more or less where we want to be:
Currently, NaN boxing from the
boxing
crate doesn't work on WASM. So we can't use that. We're still at major performance wins from the Janet interpreter.The memory layout here is more or less what we want/need. That said, keywords and interned use
&'static str
s rather than indexes. We need them to do their thing outside of aChunk
.Closing this for now, since we're more or less where we need to be. Pulling this out into smaller issues.