Draft
Conversation
Change slot sizes from {40,80,160,320,640} to {64,128,256,512,1024}.
BASE_SLOT_SIZE is now 64 (2^6) and all pool sizes are powers of 2,
enabling bit-shift slot indexing instead of magic number division.
Replace slot_div_magics[] multiply-and-shift with simple right shift.
Simplify heap_add_page() alignment to a single bitmask round-up.
Pool 0 aligns to cache line boundaries and embeds more objects
(strings: 39 vs 15 chars, arrays: 6 vs 3 elements, ivars: 6 vs 3).
On 32-bit, sizeof(VALUE) is 4 so objects are roughly half the size of 64-bit. Use BASE_SLOT_SIZE_LOG2=5 (32 bytes) instead of 6 (64) to keep slot sizes proportional to pointer width.
RFLOAT mostly
because BASE_SLOT_SIZE is now 32 bytes, it's no longer suitable for use in tests that use it to assume the size of most RVALUE objects, like strings
When RVALUE_OVERHEAD is large (debug builds with RACTOR_CHECK_MODE + GC_DEBUG), the smallest size pool's usable size can be less than sizeof(struct RBasic). The capacity calculation underflows: (8 - 16) / 8 → 0xFFFF (via size_t wraparound, truncated to uint16_t) Since shape_grow_capa iterates capacities from index 0, the garbage 65535 at capacities[0] poisons all ivar capacity growth, causing a buffer overflow in the RUBY_DEBUG assertion that fills unused capacity with Qundef.
When RVALUE_OVERHEAD > 0 (GC_DEBUG, RACTOR_CHECK_MODE), heap[0]'s usable space can equal sizeof(struct RBasic), leaving zero bytes for instance variables. The capacity was incorrectly set to 1, allowing the shape system to embed an IV that overflows into the overhead area. Change the fallback capacity to 0 and switch shape_grow_capa to count-based iteration so that a zero capacity is not confused with the array sentinel.
rb_obj_embedded_size(0) returned sizeof(struct RBasic), which is too small on builds with RVALUE_OVERHEAD (GC_DEBUG) where heap[0] has no usable space beyond RBasic. The as.heap variant needs at least one VALUE of space for the external IV pointer. Clamp the minimum fields_count to 1 so T_OBJECT allocations always request enough space for the as union.
This assumes that the typical allocation pattern is going to build way more smaller objects than large (>512 byte) objects for most cases.
because this varies by size pool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This does not contain the 48 byte size pool, that's on another branch on top of this one.
This is very WIP