variable.c: add object shapes for MRB_TT_OBJECT IV storage

Introduce "object shapes" (hidden classes) that share IV key
layouts across objects with the same instance variable assignment
order. This eliminates per-object key storage overhead.

Memory savings: ~22% heap reduction for object-heavy workloads
(e.g., 150k objects with 2-6 IVs). Per-object: 40->24 bytes
for 2 IVs. Objects exceeding 16 IVs or using
remove_instance_variable fall back to traditional iv_tbl.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-02-27 08:29:46 +09:00
parent b4d2524fb4
commit 8d10056aff
6 changed files with 404 additions and 13 deletions
+2
View File
@@ -325,6 +325,8 @@ typedef struct mrb_state {
struct mrb_mt_rom_list *rom_mt; /* heap-allocated ROM wrappers (freed at close) */
struct mrb_iv_shape *root_shape; /* root of IV shape tree */
void *ud; /* auxiliary data */
#ifdef MRB_FIXED_STATE_ATEXIT_STACK