Closed kyren closed 6 days ago
d559a3ac859b8deb7b3154996f5cd565e0fea6e1 was a drive-by change because I was manually testing allocation metrics and noticed it.
If we all think it's stupid I can drop it.
There are ways in the future that we might be able to reduce the size of DynamicRoot
so that it's only two or one machine words again, but they're not free either, and 3 machine words is not that big.
Especially with the change to use an embedded free list, I think this is a strict improvement. The only way the old way is potentially better is in the case where most of what you're doing is cloning (rather than creating, destroying, or accessing) DynamicRoot
handles, which seems unlikely.
Downsides:
1) Stashed values must be
Gc<'gc, T>
, which is less flexible. 2)DynamicRoot
types are larger, 2 pointers and a usize instead of 1 pointer.Upsides:
1) Amortized allocation. Dropping and recreating a
DynamicRoot
does not allocate. Previously, always allocated anRc
and pushed to an internalVec
, now only pushes to an internalVec
. 2) Single allocation block. All reference counts and root pointers kept in a singleVec
. 3) No double indirection duringDynamicRootSet::fetch
.DynamicRootSet::fetch
now checks one pointer field for equality (theslots
field) and returns another pointer field (theroot
field) without dereferencing anything. 4) Not really any more complicated, and handling the allocation metrics is much simpler.