Skip to content

Preserve per-entry stored digests for independent Hash lookups - #383

Merged
284km merged 6 commits into
mainfrom
codex-misc-hash-entry-digests
Nov 28, 2026
Merged

284km merged 6 commits into
mainfrom
codex-misc-hash-entry-digests

Conversation

@284km

@284km 284km commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

A mutable native key could become findable through the index-off walk, or a later key mutation could undo a pending value overwrite. Preserve each entry's insertion-time digest and latest value across mutation, copying, deletion and rehashing on both engines.

A one-entry mutable-key Hash now retains only its saved native digest beside the existing pair list and value index. Per-entry vectors and collision metadata are created when a second entry is inserted. Promotion uses the original digest even if the first key has changed. Copying takes that saved association directly and builds the destination once, instead of constructing and immediately discarding an index from the key's current contents.

Larger mutable buckets keep stable native entry identifiers. Unique buckets verify their stored key and defer values in the index; historical digest collisions use ordered per-entry values. Overwrites do not republish the pair list, ordinary frozen String keys keep indexed lookup, and literal/deletion collision paths compare actual keys. Native Hash-key digests remain content based and order independent.

Index-off membership follows actual pair order and saved digests independently of the bucket index. Deferred values are shared authoritative storage. The singleton digest table holds native text only, follows the existing index-release lifecycle, and is compacted with Hash metadata. No new Val root or exemption is added.

Clean Ruby 4.0.10 through tools/ref_ruby.sh. Current-main control 8edcf95; previous implementation integrated with the same main in d1ac9a9. All three are ordinary O2 with pinned compiler 9dec2ff6 and mgz 661a01d8.

Corpus 1139 adds singleton overwrite/copy/GC, mutation before dup/clone/replace, promotion, historical collisions, deletion and reuse. Together with related fixtures and the mutation/collision probes, 88 strict stdout/stderr/status comparisons pass across previous/candidate, evaluator/VM, index ON/OFF and the applicable normal/stress-GC configurations. Eight additional String-key construction/copy/freezing controls also match, for 96 comparisons total.

  • sh run_corpus.sh --both: 1037/1037 PASS, exit 0.
  • MERE_RUBY_VM=1 sh run_corpus.sh --both: 1037/1037 PASS, exit 0.

The small-case benchmark uses 20000 iterations and parsed --seed=1 with MERE_RUBY_GC_TIGHT=1. Each phase and engine has three alternating runs. Instructions below subtract that phase's three-run empty-loop median; creation includes its Array key, and create + dup includes both operations. These are operation costs with fixed process/loop work removed.

Engine / operation Main / previous / candidate adjusted instructions Previous / candidate vs main
Evaluator / create 548483677 / 793381134 / 560580782 +44.650% / +2.206%
Evaluator / create + dup 992390656 / 1834406301 / 972264148 +84.847% / -2.028%
Evaluator / Symbol create + dup 391039422 / 390767873 / 386541375 -0.069% / -1.150%
VM / create 586462768 / 822823365 / 593770495 +40.303% / +1.246%
VM / create + dup 1006545477 / 1859679864 / 997148149 +84.759% / -0.934%
VM / Symbol create + dup 430662982 / 432581660 / 429687342 +0.446% / -0.227%

Whole-process RSS is the maximum of all three samples, in bytes. The small mutable cases remain about 1–2 MiB above main; this change does not claim lower peak memory. All raw samples, including main and previous, are retained.

Engine / operation Main / previous / candidate max RSS bytes Candidate samples
Evaluator / small_create 104923136 / 102973440 / 107036672 [106921984, 107020288, 107036672]
VM / small_create 106381312 / 104382464 / 107462656 [107462656, 107462656, 107462656]
Evaluator / small_dup 105562112 / 104153088 / 107003904 [107003904, 106889216, 106938368]
VM / small_dup 106561536 / 105152512 / 108019712 [107970560, 107970560, 108019712]
Evaluator / small_symbol_dup 88309760 / 88440832 / 88588288 [88522752, 88539136, 88588288]
VM / small_symbol_dup 92520448 / 92733440 / 93028352 [92930048, 93028352, 92913664]

The other committed benchmark modes retain three alternating main/previous/candidate runs with tight GC and parsed seed 1. Instructions include startup/construction/checksum work. The timed overwrite/read loops exclude those phases; shared-machine seconds are diagnostic. Both 4000 and 8000 keys are retained to guard the previously repaired growth and overwrite paths.

Engine / workload / count Candidate vs main / previous instructions Main / previous / candidate max RSS bytes Candidate loop seconds
Evaluator / churn / 10000 -3.176% / -21.120% 105889792 / 104349696 / 106037248 —
VM / churn / 10000 -2.934% / -19.903% 105807872 / 104398848 / 105070592 —
Evaluator / mutable_read / 10000 -2.017% / -2.869% 86212608 / 86343680 / 86261760 —
VM / mutable_read / 10000 -2.153% / -3.314% 87523328 / 87572480 / 87539712 —
Evaluator / mutable_write / 10000 -1.561% / -5.427% 86867968 / 87408640 / 86867968 —
VM / mutable_write / 10000 -2.104% / -5.840% 88178688 / 88637440 / 88195072 —
Evaluator / hash_key_read / 10000 -2.994% / -4.285% 86278144 / 86441984 / 86212608 —
VM / hash_key_read / 10000 -2.465% / -3.870% 87588864 / 87687168 / 87556096 —
Evaluator / mixed_growth / 4000 +0.933% / -0.035% 87801856 / 88227840 / 88342528 —
VM / mixed_growth / 4000 +0.988% / +0.054% 87998464 / 88391680 / 88719360 —
Evaluator / immutable_growth / 4000 +0.549% / -0.026% 87834624 / 87982080 / 88064000 —
VM / immutable_growth / 4000 +0.147% / -0.087% 88080384 / 88211456 / 88408064 —
Evaluator / large_literal / 50000 +0.377% / -0.273% 286228480 / 292569088 / 293027840 —
VM / large_literal / 50000 +0.382% / -0.035% 283557888 / 290897920 / 291323904 —
Evaluator / array_overwrite / 4000 +4.650% / +0.083% 90537984 / 93011968 / 93110272 0.009205
VM / array_overwrite / 4000 +4.366% / +0.228% 91684864 / 92569600 / 92864512 0.009978
Evaluator / array_overwrite / 8000 +7.264% / -0.078% 95305728 / 98975744 / 99057664 0.021036
VM / array_overwrite / 8000 +7.070% / +0.178% 95780864 / 98287616 / 98533376 0.020745
Evaluator / array_first_overwrite / 4000 +3.587% / +0.007% 90439680 / 92422144 / 92520448 0.009827
VM / array_first_overwrite / 4000 +3.778% / -0.044% 91570176 / 90849280 / 91013120 0.010165
Evaluator / array_first_overwrite / 8000 +6.047% / -0.092% 93536256 / 97533952 / 97632256 0.023631
VM / array_first_overwrite / 8000 +5.946% / +0.156% 95371264 / 94879744 / 95043584 0.022784
Evaluator / mixed_string_overwrite / 4000 +0.984% / -0.300% 91308032 / 91832320 / 91963392 0.004794
VM / mixed_string_overwrite / 4000 +0.747% / +0.110% 92356608 / 92880896 / 93011968 0.006107
Evaluator / mixed_string_overwrite / 8000 +1.285% / +0.100% 94519296 / 95518720 / 95584256 0.010280
VM / mixed_string_overwrite / 8000 +1.198% / +0.082% 96714752 / 97533952 / 97714176 0.013544
Evaluator / mixed_string_read / 4000 +0.445% / +0.054% 90849280 / 91308032 / 91439104 0.012327
VM / mixed_string_read / 4000 +0.781% / +0.139% 91766784 / 92307456 / 92422144 0.014629
Evaluator / mixed_string_read / 8000 +1.132% / -0.049% 93929472 / 94994432 / 95059968 0.023134
VM / mixed_string_read / 8000 +1.265% / -0.245% 94568448 / 96468992 / 96583680 0.023887

The larger Array-key overwrite rows retain the prior correctness cost versus main (up to about 7% whole-process instructions here); this singleton follow-up changes their instructions by less than 0.3% versus the integrated previous implementation. The 50000-key literal still has the previously disclosed several-MiB cost versus main. No storage bound or assertion is relaxed.

Original CRuby files, selectors, assertions and resource bounds are unchanged. Reference/main/candidate comparisons use tight GC and parsed --seed=1. All 25 selected executions complete with the same reference summaries. The replace resource retains its original 676 keys, 10000 warmup and 500000 replacements; allocation tests retain their original 100000-element Array and 100000-key Hash. No full unit or Rails component suite was run.

Hash functional original selection: ruby/test_hash.rb /test_(rehash|s_AREF_key_tampering|shift|dup|clone|replace)\z/.

Hash replace resource original selection: ruby/test_hash.rb /test_replace_memory_leak\z/.

Hash key equality original selection: ruby/test_hash.rb /test_(eql|hash_hash|recursive_key|dup_equality)\z/.

Array to_h original selection: ruby/test_array.rb /test_to_h\z/.

Allocation literals original selection: ruby/test_allocation.rb /test_(array_literal|hash_literal)\z/.

Summary cells: tests / assertions / failures / errors / skips.

Scope Ruby Main E Candidate E Main VM Candidate VM
Hash functional 12 / 72 / 0 / 0 / 0 12 / 72 / 0 / 0 / 0 12 / 72 / 0 / 0 / 0 12 / 72 / 0 / 0 / 0 12 / 72 / 0 / 0 / 0
Hash replace resource 1 / 3 / 0 / 0 / 0 1 / 3 / 0 / 0 / 0 1 / 3 / 0 / 0 / 0 1 / 3 / 0 / 0 / 0 1 / 3 / 0 / 0 / 0
Hash key equality 8 / 20 / 0 / 0 / 0 8 / 20 / 0 / 0 / 0 8 / 20 / 0 / 0 / 0 8 / 20 / 0 / 0 / 0 8 / 20 / 0 / 0 / 0
Array to_h 2 / 16 / 0 / 0 / 0 2 / 16 / 0 / 0 / 0 2 / 16 / 0 / 0 / 0 2 / 16 / 0 / 0 / 0 2 / 16 / 0 / 0 / 0
Allocation literals 2 / 8 / 0 / 0 / 0 2 / 8 / 0 / 0 / 0 2 / 8 / 0 / 0 / 0 2 / 8 / 0 / 0 / 0 2 / 8 / 0 / 0 / 0

Measured /usr/bin/time -l driver maxima (not a repeated process-family RSS claim):

Driver max RSS bytes Ruby Main E Candidate E Main VM Candidate VM
Hash functional 23052288 160923648 161169408 179765248 180240384
Hash replace resource 86212608 160858112 161136640 179830784 180011008
Hash key equality 23035904 160940032 161169408 179896320 180207616
Array to_h 24657920 167690240 167968768 214761472 214941696
Allocation literals 76546048 311541760 322928640 318193664 329285632

Pre-existing mutated-key differences through hset-based delete_if/reject!/select!/keep_if/compact!/merge and values_at/merge!/transform_values!/select remain follow-ups. The CRuby small-table growth/rehashing detail is also separate. This PR does not claim those differences are repaired.

Candidate O2 SHA-256 d715bcd0b8f0e979b1b7a28b73d3ee59766c5257977476f65c6a61d8111adde2. Historical measurements remain retained with their original sources; all fresh results above use the new integrated runtime.

Source gates gc_roots, dup_defs, dead_defs, meth_writes, iv_door, name_spec, rx_caps, ns_names, name_len, generated-C bracket depth and strbuf_region: PASS. The packed-GC probe passes O2 and ASan/UBSan. Full and explicit completed record_hygiene and staged/unstaged whitespace: PASS. Code and its completed record are pushed together; no workflow changes or reference gem installation.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 7450c284f2c17b4bdee6cd20dc546f0fdaa41841 against current main c913da278ac8daabbc02d4d78d63b5ca85131ea9 and its fetched base/history.

The per-entry representation and copy regressions address the original mutable-key lookup problem, and corpus 1139 usefully covers duplicate key-object entries and independent rehashing. Two Major/P2 issues remain: an overwrite can be lost in the previously correct disabled-index configuration, and mixed-key insertion becomes quadratic. Both are detailed inline with reproductions and baseline comparisons.

Independent validation: fresh ordinary O2 head build using CI-pinned Mere 9dec2ff6 and verified mgz 661a01d8; current-main comparison reuses a tested O2 binary whose 568 runtime/build inputs were verified byte-identical to current main. Nine selected corpus files, including 1139/1137/493/1051/288, match Ruby 4.0.10 stdout, stderr and exit status in all four engine/index configurations (36/36). A deterministic 160-operation copy/mutate/rehash probe also matches in all four configurations. The separate overwrite reproducer fails as described inline; other pre-existing differences in exploratory probes were compared with main and are not new findings. Duplicate/dead definitions, name-length guards, method-write generations, GC roots and emitted-C bracket depth (155) pass. Performance figures use three alternating main/head executions per configuration, all exiting 0; they measure the insertion loop with Process.clock_gettime. Initial external RSS collection was unavailable because the sandbox denied time's sysctl query; no RSS result or program failure is inferred from that wrapper error.

I did not independently rerun the full corpus or complete original CRuby test file. Hosted Linux/macOS builds and another macOS suite are still running, with reference/other suites queued and downstream core acceptance incomplete. No merge: these findings and the recorded hold_all_merges / new_failure_review_required block it. Latest main CI run 45954384464 still has zero generated jobs. Previously reviewed open PRs, including the draft, were also considered under the hold; merelang/mere has no open PRs. COMMENT because the authenticated account owns the PR.

Comment thread m_state.mere Outdated
(let current = hkey_dig id k in
let d = vec_get rows pos in
let ix = map_get hash_index id in
Cons (k, Cons ((if str_len d > 0 && str_eq d current && map_has ix d then map_get ix d else v), hstale_vals_at id t rows (pos + 1))))

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major / P2] Preserve the overwritten value even after its key changes. The d == current condition leaves the old pair value in place when an overwrite is pending and the key mutates before hderef. For example: key = [1]; h = {key => :old}; 10.times { |i| h[i] = i }; h[key] = :new; key << 2; p [h.values.first, h.dup.values.first]. Ruby 4.0.10 prints [:new, :new]; this head prints [:old, :old] in both engines and both index configurations. In particular, with MERE_RUBY_NO_HASH_INDEX=1, current main prints the correct [:new, :new], so this PR introduces value loss in the independent walk. Current main already has the enabled-index failure; that existing baseline is not being reported as a new regression. Use the entry's stored digest to recover its latest value regardless of the key's current digest: mutation should affect keyed lookup, not undo an earlier value assignment. Add an overwrite-then-mutate regression before values/copy settlement.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0cce4e8. Mutable native-key overwrites now update their actual stored entry. Mutation cannot undo an earlier assignment, and distinct entries sharing a historical digest retain separate values through settlement, copies, deletion and rehash. The exact overwrite reproducer returns [:new, :new] on both engines and both index configurations; the stronger historical-digest reproducer also matches Ruby in all four.

Comment thread main.mere Outdated
then (if hidx_has hid (hkey_dig hid k)
if hidx_on hid && (if str_eq (hkey_dig hid k) "" then false else true)
then (if (if map_has hentry_rows hid then
(let (found, _) = hentry_lookup hid ident (hderef hid) k in found)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major / P2] Keep index misses fast when a hash contains a mutable key. This branch checks whether the hash has digest rows, so one Array key forces every subsequent insertion—even a new Integer key—to call hderef and scan all existing pairs. Thus h = {[] => :mutable}; 4000.times { |i| h[i] = i } now rebuilds/walks the growing table on every insertion. With fresh ordinary O2 candidate and verified current-main O2 builds, three alternating runs per engine gave insertion-loop medians of 0.00381s → 0.39110s (evaluator) and 0.00432s → 0.44250s (VM), about 103× slower. The same workload starting with an immutable Symbol key stays around 4–5ms on both builds. These are shared-machine wall times, supported by the newly unconditional O(n) path. Check index membership before settling/scanning, and reserve entry verification for queries that actually need it; an absent indexed digest can queue immediately. Please include a mixed mutable/immutable-key growth benchmark, since the one-entry mutable_read/churn benchmarks do not cover this quadratic path.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0cce4e8. Index membership is checked before settling/scanning; immutable misses retain their indexed insertion path even when a mutable key exists. The committed benchmark includes mixed_growth and immutable_growth. Three alternating current-main/reviewed/fixed runs at 1000/2000/4000 insertions are posted; fixed 4000-loop medians are 0.005932s evaluator / 0.004488s VM. Validation main 491cc5c is merged, with fresh full corpus sweeps on both engines, original Hash tests, gates, record_hygiene and tight-GC seed=1 RSS in the updated description.

@284km

284km commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

Both Major findings are fixed locally and validation main 491cc5ca is integrated. Native mutable-key overwrites update the actual entry, including distinct entries sharing a historical digest; indexed misses keep the fast insertion path.

The pinned-main candidate passes 36/36 related corpus comparisons across both engines and both index configurations. Original CRuby Hash selections pass unchanged on reference, matching main and candidate: functional 12 tests / 72 assertions, original replace resource 1 / 3, and key equality 8 / 20, with tight GC and parsed --seed=1. Three alternating-pair cost measurements are complete; exact-head reproducer/scaling supplements and fresh complete corpus sweeps are running through the shared two-slot admission queue.

I will push the integration, fixes and completed loop record together after those checks finish. No partial sweep is counted as acceptance, and no resource bound or assertion is changed.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of head 0cce4e80 (previous review: 7450c284).

Earlier findings

  • [Major] Value loss after a mutable key is mutated (m_state.mere): resolved. I ran the exact reproducer on the head build. It prints [:new, :new] in all 8 configurations (evaluator/VM × index on/off × MERE_RUBY_GC_STRESS=1 off/on). I also ran 49 nearby variants against Ruby 4.0.10: mutation then lookup/assign/delete, delete after the key is restored, dup + rehash, rehash then assign, compare_by_identity, a hash with both mutable and immutable keys, several entries that share one stored digest (the hash value recorded when the key was stored), Hash keys, unfrozen String keys via Hash[], store, replace, clone, GC.start in the middle. The head gives the same output in all 8 configurations. Main is wrong on 33 of the 49 in at least one configuration. The head fixes 22 of those 33. No variant got worse than main. The other 11 are also wrong on main; see the Suggestion below.
  • [Major] O(n) insert once a mutable key is present (main.mere): resolved for the reported case. A miss (a new key) now checks the index first. h = {[] => 0}; 8000.times { |i| h[i] = i } takes the same time as main on both engines (evaluator ~0.007 s, VM ~0.017 s, both builds). But a hit (overwriting an existing key) still has an O(n) path. See the new Major below.

New findings

  • [Major] Overwriting a key in a hash that has a mutable-key entry copies the whole pair list. Reading a String key from such a hash walks the list. Details and numbers are inline. Two causes. (1) hput_or_queue calls hst_publish on every mutable-key hit, and map_set deep-copies the list. (2) hentry_query returns true for every String query, so String reads take the walk even when every stored String key is frozen. Overwrites go from flat to about 150–250× slower at 8,000 keys, and max RSS goes from ~75 MB to ~390 MB. On the other hand, Array-key reads got much faster than main (group_by with Array keys is ~9× faster, a Hash.new(0) counter with Array keys ~6×). So this is a trade, not a plain loss, but the overwrite path is now quadratic where main was O(1).
  • [Minor] The index-off configuration now trusts the index on writes. Inline on hput_or_queue. MERE_RUBY_NO_HASH_INDEX=1 is the cross-check that the index agrees with the walk. The comment on hidx_use says "Writes keep maintaining it either way, so the two runs differ only in which answer is believed". With this PR, hpush_new starts an index when the switch is off (plain9 = not (hidx_on id)). hput_or_queue and hash_store_key (found9) now use hidx_on instead of hidx_use. So in the off configuration the write side also believes the index for immutable keys. A write-side index bug would now give the same wrong answer in both runs. Please route only the mutable-entry case through the new path, or update the comment and say what the off run still checks.
  • [Suggestion] Pre-existing gaps in the same area (identical on main, not caused by this PR). After k << 2 on a stored Array key, Ruby 4.0.10 answers h[k] → nil. Head and main both answer the old value after delete_if, reject!, select!, keep_if, compact! and merge (these paths go through hset, which drops the index and the entry digests). values_at, merge!, transform_values! and select also differ from Ruby in the same way. One more case, five Array keys that all had the stored digest of [0], differs too. There CRuby recomputes hashes when its small table grows, so it is an implementation detail. A follow-up PR could keep entry digests through hset. I do not block on this.

Measurements (head build vs main 491cc5ca build, O2)

Bench file bench/hash_entry_digests.rb, MERE_RUBY_GC_TIGHT=1 --seed=1, two runs each, retired instructions:

workload evaluator VM
churn 10000 +10.4% +9.3%
mutable_write 10000 +2.3% +2.0%
mutable_read, hash_key_read, mixed_growth, immutable_growth within ±0.6% within ±0.6%

Max RSS on these is about +0.9 MB on every workload, and churn is −4 MB. This matches the PR description.

Extra loop timings (wall time inside the loop, MERE_RUBY_GC_TIGHT=1, 3 alternating runs, shared machine, so ratios matter more than absolute values):

loop, 8000 keys main head
h[[i]] = i+1 over 8000 Array keys (eval / VM) 0.017–0.041 s / 0.017–0.021 s 2.2–2.9 s / 2.8–3.1 s
same, max RSS 75 MB / 79 MB 387–390 MB / 393–395 MB
String keys overwritten, hash also has [1] => 0 (eval / VM) 0.010–0.013 s / 0.010–0.012 s 2.5–3.3 s / 2.9–3.3 s
String keys read with unfrozen copies, hash also has [1] => 0 0.012–0.022 s 0.34–0.40 s
Integer keys overwritten, hash also has [1] => 0 0.006–0.011 s 0.008–0.013 s
String keys overwritten, no mutable key 0.016–0.020 s 0.013–0.016 s
group_by { [x % n] } over 32000 items 31.3 s 3.6 s

Corpus 1139 and local results

corpus/1139_hash_walk_uses_each_entry_stored_digest.rb matches Ruby 4.0.10 (stdout + stderr + exit status) in all 8 configurations above. Main fails it (lines 5–6 differ), so it does test the change. The author posted local results in the description: full corpus 1032/1032 on both engines, selected CRuby test_hash.rb cases, the cost table and the scaling table. The scaling table covers only the miss path, not overwrites or String reads.

Not checked

I did not run the full corpus or the CRuby test files myself. I used the author's head build after checking that its sources are clean at 0cce4e80 and older than the binary. I did not build my own.

CI

At review time: 4 workflows passed (Linux build dependency controls, NKF Wasm engine, Rake suite, Delegation and URI gem suites). Gem suites was in progress. CI, Runtime load path controls, Additional gem suites and Small pure Ruby gem suites were queued.

Comment thread main.mere Outdated
else if hentry_query hid k then
(let (found, pairs) = hentry_put hid ident (hderef hid) k v in
if found then
(let _ = hst_publish hid pairs in

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major] A mutable-key hit copies the whole pair list on every write. hst_publish is map_set hash_store id xs. That map_set deep-copies the list (sample shows mere_map_int_list_Val_set → __mcopy_Val under hput_or_queue as the top cost). So each overwrite is O(n) time and O(n) allocation, even when the matching pair is the first one. The hash_stale design exists to avoid exactly this (see the "AN IMMUTABLE-KEY OVERWRITE IS WRITTEN TO THE INDEX ONLY" comment in m_state.mere).

Reproducer:

h = {}; ks = Array.new(8000) { |i| [i] }
ks.each_with_index { |k, i| h[k] = i }
t = Process.clock_gettime(Process::CLOCK_MONOTONIC)
ks.each_with_index { |k, i| h[k] = i + 1 }
p Process.clock_gettime(Process::CLOCK_MONOTONIC) - t

Main: 0.017–0.041 s, max RSS 75 MB. Head: 2.2–2.9 s, max RSS 387 MB (evaluator, MERE_RUBY_GC_TIGHT=1). The VM is the same: 0.017–0.021 s → 2.8–3.1 s, 79 → 393 MB. At 4000 keys it is 0.007–0.015 s → 0.56–0.67 s, so it grows quadratically. Writing one key 4000 times in an 8000-entry Array-keyed hash takes 1.4 s even when the key is the first pair. The same happens to String keys in a hash that also holds one Array key, because hentry_query is true for every String (next comment).

Possible fixes: keep the value change out of the list (the index or a per-entry value row, folded later like hstale_fold), or update the pair in place without republishing. Only walk when the query digest is shared by more than one entry, or when it belongs to an entry whose key is mutable. Please add an overwrite-heavy workload (Array keys, and String keys next to one Array key) to bench/hash_entry_digests.rb.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7567153. Unique mutable buckets now verify a cached stored key and update their deferred indexed value without publishing the whole pair list. Only a shared stored digest needs per-entry deferred values, folded when the actual pair list is requested. Stable entry identifiers preserve these values through deletion and copying. The committed benchmark now measures Array-key overwrites, repeated writes to the first key, String-key overwrites, and 4000/8000-key scaling with three alternating main/reviewed/fixed pairs and tight-GC seed=1 RSS. Fresh complete corpus sweeps, original selected CRuby comparisons, source gates and record_hygiene are posted.

Comment thread main.mere Outdated
match key with
| VArr _ -> map_len hentry_rows > 0 && map_has hentry_rows hid
| VHsh _ -> map_len hentry_rows > 0 && map_has hentry_rows hid
| VStr _ -> map_len hentry_rows > 0 && map_has hentry_rows hid

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major, same root as the comment above] Every String query takes the walk once the hash has entry rows. This arm does not look at whether the stored String keys are mutable. Hash#[]= stores a frozen copy of an unfrozen String key, so in the common case none of them are. With h = {[1] => 0} plus 8000 String keys, reading all keys with unfrozen copies (h[k.dup]) takes 0.34–0.40 s on head and 0.012–0.022 s on main (both engines). Overwrites of those String keys go through hentry_put and copy the list: 0.010–0.013 s → 2.5–3.3 s. Integer and Symbol keys in the same hash are unaffected. Could hentry_query check whether the query digest belongs to a mutable entry (for example, a per-hash set or count of digests owned by mutable entries)? Then frozen-String and other immutable hits keep the O(1) index path.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7567153. Ordinary frozen String keys beside an Array key remain on the indexed path. Only a String bucket that contains mutable entry history needs stored-key verification. The new benchmark includes reads with unfrozen copies and overwrites beside an Array key, plus a plain String-key control; all timing/instruction/RSS results are in the description. Fresh complete corpus sweeps, original selected CRuby comparisons, source gates and record_hygiene are posted.

Comment thread main.mere Outdated
else (let _ = hput_new_check hid in let _ = hpush_new hid k v in v))
// is the whole answer for an immutable key. Native mutable hits must update
// their actual entry, since a stored digest can belong to multiple entries.
if hidx_on hid && (if str_eq (hkey_dig hid k) "" then false else true)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Minor] The index-off run no longer checks the write side independently. This line and found9 in hash_store_key now use hidx_on instead of hidx_use. Also hpush_new now starts an index when MERE_RUBY_NO_HASH_INDEX=1 (plain9 = not (hidx_on id)). Together, with the switch off, immutable-key membership on writes also comes from the index. The hidx_use comment says the two runs "differ only in which answer is believed". That is no longer true for writes, so a write-side index bug would give the same wrong answer in both runs. If only mutable-entry hits need the digest-aware path in the off run, please keep hidx_use for the rest. Otherwise, update that comment to say what the off run still verifies.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7567153. Ordinary write membership again uses hidx_use and the independent walk in the off configuration. Native mutable entries use the per-entry stored-digest walk there. The source comment now explicitly distinguishes independent membership from the shared maintained/deferred value storage. Corpus 1139 and the mutation/copy/GC trace pass on both engines with the index on/off and GC stress on/off. Fresh complete corpus sweeps, original selected CRuby comparisons, source gates and record_hygiene are posted.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up on head 0cce4e8, fetched PR base 491cc5c and latest main 856e61b.

The earlier overwrite-loss finding is fixed: its exact reproducer now returns [:new, :new] in both engines with indexing on/off. The earlier unconditional pair scan on indexed insertion misses is also removed; mixed-key growth controls complete. Keeping actual mutable-entry values separate from the index addresses the historical-digest problem. Two new Major/P2 regressions remain: canonical digest collisions collapse distinct identity-mode Hash keys during literal construction, and deletion can remove the wrong entry. Reproductions and fixes are inline; neither duplicates the earlier findings. I also read the newer review 6094799037: its overwrite/String-query performance and index-off comments are already recorded and are not repeated here.

Independent validation: 36/36 selected corpus stdout/stderr/exit comparisons match Ruby 4.0.10 across both engines and index configurations. The new combined collision reproducer matches Ruby on the exact PR base in all four configurations and fails on this head in all four. Duplicate/dead-definition gates pass. Three mixed-growth runs per size (1000/4000) and engine complete; shared-host timings are diagnostic, not controlled performance acceptance.

Build provenance: the candidate reuses O2 binary SHA256 dbc94782cd3d96a51b8df13a8613379ff98a31b0f86c741ee87d023462c1d7a9 after verifying runtime/native/build inputs, imported mgz modules and byte-identical C freshly emitted from this exact head with pinned Mere 9dec2ff6. The base control reuses its recorded O2 binary after checking its source inputs against fetched base 491cc5c. Latest main changes keyword-packet ownership; the affected Hash literal/digest/equality/deletion paths are unchanged from that base. A separate latest-main O2 build emitted C but did not finish compilation and was stopped; it is not a passing build or an integration test. Initial native-fixture failures from placing the candidate outside its header/library layout were corrected and all four reruns match Ruby; they are not PR findings. No independent full corpus, complete original CRuby Hash file, cross-platform resource acceptance or completed latest-main build is claimed.

No merge: both new findings and the recorded hold_all_merges/new_failure_review_required block it. Hosted builds and required downstream acceptance are incomplete, with running jobs as well as queues; the runner-queue exception does not apply. Previously reviewed open PRs and drafts were considered under the same hold. COMMENT because this account owns the PR.

Comment thread m_state.mere
else
(let _ = map_set hkey_busy busy true in
let (valid, pairs) = hkey_hash_pairs (hderef_fwd id) Nil in
let answer = (if valid then "H" ++ str_join "" (hkey_hash_sort pairs) else "") in

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major / P2] Preserve distinct identity-mode Hash keys during literal construction. Sorting the encoded pairs gives these non-eql? keys the same digest, but the existing hash_merge consumer deduplicates solely by digest, without checking equality:

normal = {a: 1, b: 2}
identity = {b: 2, a: 1}.compare_by_identity
h = {normal => :normal, identity => :identity}
p [h.size, h[normal], h[identity]]

Ruby 4.0.10 and the fetched base print [2, :normal, :identity]; this head prints [1, :identity, nil] in both engines with indexing on/off. The first entry's value is lost while constructing the literal. The new native equality helper correctly distinguishes the nonempty identity modes, but hash_merge never calls it on this path. Make the digest's consumers handle collisions with the same key-equality rule (or preserve the relevant identity distinctions in the representation), and add this literal regression alongside the reordered-Hash coverage.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7567153. Literal construction now keeps collision buckets and compares actual keys rather than treating a matching digest as equality. The digest remains content based: mode flips and replacement of an identity key by an equal-content object retain the appropriate outer bucket. Corpus 1139 includes the exact normal/identity literal regression, shared versus distinct identity-key objects, empty Hash keys and the mode-change controls. A 50000-key ordinary literal benchmark and original allocation cases guard the common construction path. Fresh complete corpus sweeps, original selected CRuby comparisons, source gates and record_hygiene are posted.

Comment thread m_state.mere Outdated
match ys with
| Cons (key, Cons (value, tail)) ->
let d = vec_get old i in
if not removed && str_eq d query && str_eq (hkey_dig id key) query then go tail (i + 1) true

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major / P2] Check key equality before removing a digest-matching entry. Matching stored/current digests does not identify an entry uniquely. With the same two keys as above, inserting separately preserves both entries, but deletion removes the wrong one:

h = {}
h[normal] = :normal
h[identity] = :identity
p h.delete(identity)
p h.values

Ruby and the fetched base print :identity followed by [:normal]; this head prints :identity followed by [:identity] in all four engine/index configurations. Lookup selects the identity-mode key correctly, but this loop removes the earlier ordinary key because their canonical digests match. Include the same hkey_same/identity-mode comparison used by hentry_lookup when selecting the pair to delete, preserving the other entry and its stored digest. This is separate from the literal-construction path: it reproduces even when both entries were inserted successfully.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7567153. Deletion now requires the same hkey_same comparison used by lookup, in addition to the stored digest match. It removes only the selected entry, updates/demotes that collision bucket and preserves the stable identifiers of every remaining entry. The exact separately-inserted normal/identity key reproducer now preserves the ordinary entry, on both engines and both index configurations. Fresh complete corpus sweeps, original selected CRuby comparisons, source gates and record_hygiene are posted.

@284km

284km commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

I have read the new overwrite/String Majors and the index-off Minor on 0cce4e80. A separate local follow-up replaces whole-pair publication on hits with deferred indexed values for unique stored digests, and per-entry deferred values only for historical digest collisions. Ordinary frozen String keys retain their indexed lookup path. Stable entry identifiers preserve the associations through deletion and copying.

The off configuration is also being restored to independent membership decisions for ordinary writes, with an explicit description of the shared deferred value storage. Corpus 1139 now exercises many-key overwrites, mixed String keys, deletion followed by insertion, collection and copies. The benchmark adds Array overwrites (including repeated writes to the first key), String reads/overwrites beside an Array key, and immutable controls.

The prototype build and focused comparisons are queued under the shared machine-wide two-run cap. I will post the actual 4000/8000-key alternating-pair timing/instruction/RSS measurements, fresh full corpus sweeps and gates together with the fix. The new findings remain open until that validation is complete.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of head 75671534 (my previous review: 0cce4e80).

I built this head myself (O2, tools/build.sh, Mere compiler 9dec2ff6, mgz 661a01d8). The control is a clean O2 build of the merge base, main 491cc5ca. The reference is Ruby 4.0.10. "8 configurations" below means evaluator/VM × index on/off (MERE_RUBY_NO_HASH_INDEX=1) × MERE_RUBY_GC_STRESS=1 off/on.

Earlier findings

  • [Major] An overwrite copied the whole pair list, and String reads walked the pairs: resolved (verified by running). With 8,000 keys, MERE_RUBY_GC_TIGHT=1 and 3 alternating runs, the head now matches main. Times are main → head, in seconds inside the loop:
    • Array-key overwrites: evaluator 0.013–0.015 → 0.018–0.019, VM 0.015–0.022 → 0.018–0.062 (one outlier). The previous head took 2.2–3.1. Max RSS is 75 → 80 MB; the previous head used 387 MB.
    • Writing the first Array key 8,000 times: 0.011–0.015 → 0.014–0.017 (both engines). The previous head took 1.4.
    • String-key overwrites next to one Array key: 0.010–0.013 → 0.010–0.012 on both engines. The previous head took 2.5–3.3.
    • String-key reads with unfrozen copies next to one Array key: 0.013–0.016 → 0.013–0.018 on both engines. The previous head took 0.34–0.40.
    • Integer overwrites and mixed growth are unchanged.
    • Array-key reads are much faster than main: 8,000 reads take 4.4–5.0 s with 1.5–2.5 GB RSS on main, and 0.018–0.064 s with 79–81 MB on the head. group_by { [x % 2000] } over 8,000 items goes from 1.1–1.4 s / 1.78 GB to 0.13–0.20 s / 229 MB.
  • [Minor] The index-off run trusted the index on writes: resolved (verified by reading). hput_or_queue and found9 use hidx_use again for ordinary keys. Mutable entries use the stored-digest walk when the index is off. The hidx_use comment now says that only value storage is shared. hpush_new still builds an index when the switch is off, but nothing believes it for membership there. That matches the comment.
  • Bot findings from 01:21 (identity-mode Hash key literal, and delete removing the wrong entry): resolved (verified by running). Both exact reproducers match Ruby in all 8 configurations.

Digest collisions (entries with an equal stored digest but unequal keys)

I wrote 30 new cases and compared them with Ruby 4.0.10. Here "chain" means several entries that share one stored digest.

  • Chains built by mutating a stored key and then storing an equal-content key. Then overwrite, delete, delete + re-add, dup of a chain, and restoring the mutated keys.
  • Normal vs compare_by_identity Hash keys with the same content: literal, separate inserts, overwrite and delete of each.
  • Unfrozen String keys from Hash[] that were mutated and then restored.
  • Frozen String keys next to an Array key.
  • compare_by_identity hashes, a mode flip on a Hash key, and empty Hash keys.
  • A deferred overwrite (a new value kept outside the pair list until the list is needed), followed by every path that builds the pair list: dup, clone, replace, merge, each, first, inspect, Marshal, select/reject, sort_by, ==/eql?/hash, rehash, delete, shift, transform_keys, to_h, invert, values_at/fetch/dig/key.

All 30 match Ruby in all 8 configurations. Main is wrong on 6 of them. Five more cases cover String key copies, store, and keys and chain values that survive repeated GC.start. All 5 match in all 8 configurations; main is wrong on the chain-value case.

No regressions

  • The 49 cases from my previous review: the head is wrong on 11 in all 8 configurations. Main and the previous head are wrong on the same 11, so nothing got worse. Main is wrong on 33.
  • The 11 are the pre-existing gaps from my last review: mutated keys after delete_if/reject!/select!/keep_if/compact!/merge, plus values_at/merge!/transform_values!/select. There is also one CRuby small-table rehash detail. The description records them as follow-ups.
  • corpus/1139_hash_walk_uses_each_entry_stored_digest.rb matches Ruby 4.0.10 (stdout, stderr and exit status) in all 8 configurations.

New findings

  • [Suggestion] Small hashes with a mutable key cost noticeably more to create and copy. Inline on hentry_make. This is not a bug and the description discloses it (churn +21–22%). I do not block on it; it is for the owner to accept or not. Instructions per 20,000-iteration loop, with the empty-loop baseline (≈1,373M) subtracted, main → head:

    • {[i] => i}: 571M → 828M (+45%).
    • {[i] => i}.dup: 1,041M → 1,919M (+84%).
    • {a: i}.dup, the Symbol control: +4%.

    The bench churn row is 2,330M → 2,830M (+21%) on the evaluator and 2,414M → 2,907M (+20%) on the VM. mutable_write is +4%. mixed_growth is +0.6–0.8%.

  • [Suggestion] Max RSS of the 50,000-key literal is a few MB higher. large_literal 50000 uses 270.6–275.2 → 279.0 MB on the evaluator and 275.1–278.6 → 281.8–284.0 MB on the VM, two runs each. Instructions are +0.2–0.7%. The description's allocation-literals row shows the same direction (+12 MB / +7 MB). The cause is probably the per-digest pair buckets in hash_merge. It is small; I note it only so it stays visible.

Local results from the author

The description has everything I would expect: full corpus 1032/1032 on both engines, the selected CRuby test files with RSS, the cost table, and 4,000/8,000-key overwrite and read scaling against main and the previous head. My numbers agree with theirs.

Not checked

I did not run the full corpus or the CRuby test files myself.

CI

At review time, 2 workflows passed (Linux build dependency controls, NKF Wasm engine). CI and 6 other workflows were queued.

Merge readiness: no Critical, Major or Minor finding is open from my side. The two Suggestions are optional. CI has not finished yet.

Comment thread m_state.mere
let _ = values xs 0 in
map_set ix "~next" (if map_has source "~next" then map_get source "~next" else VInt (vec_len rows / 2));
let hentry_make = fn (id: int) -> fn (xs: Val list) ->
let rows = hentry_take () in

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] Creation and dup of small mutable-key hashes. Every hash that gets entry rows calls hentry_take here, which adds 4,096 to the GC pressure counter. hentry_populate then writes ~m/~s/~k/~next (and ~strings) beside the digest. For a one-pair {[i] => i} this is about +12.7k instructions per creation, and dup adds about +31k more. The churn bench row (+21%) is mostly this. Measured as 20,000-iteration loops with the loop baseline subtracted: create 571M → 828M, create + dup 1,041M → 1,919M. A Symbol-key control is +4%. Ideas, if you want them: build the metadata lazily (only when a second entry or a hit needs it); copy the source's ~ entries in hentry_copy instead of rebuilding them with hentry_populate; or charge the GC counter by the size of the rows instead of a flat 4,096. Not blocking.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recorded as a non-blocking performance follow-up. The current description and completed loop record retain the +21–22% churn cost, the mutable-write/growth figures, and the extra RSS for the 50,000-key literal. Your isolated small-hash creation/dup measurements make that remaining cost clearer. I am keeping the current correctness fix and its completed validation together on this head; lazy metadata construction and cheaper copying/GC charging can be evaluated separately against the same mutation, collision and index-off controls. The 11 pre-existing transform gaps also remain recorded, without a claim that this PR fixes them.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 490d010, with current main 8edcf95 integrated. A singleton mutable-key Hash stores only its insertion-time native digest; entry vectors/collision metadata are deferred until a second entry. Copies preserve that stored association and build the destination once.

Three alternating main/integrated-previous/fixed pairs, GC_TIGHT and parsed seed=1, 20,000 iterations with each phase's empty-loop median subtracted:

  • Creation: +44.650% -> +2.206% evaluator; +40.303% -> +1.246% VM.
  • Creation + dup: +84.847% -> -2.028% evaluator; +84.759% -> -0.934% VM.
  • Symbol create + dup remains flat (candidate -1.150% / -0.227% vs main).

Small mutable-case peak RSS remains about 1–2 MiB above main, explicitly recorded with all three samples. Larger overwrite/read instructions change by less than 0.3% versus the integrated previous implementation; 4,000/8,000-key controls and the existing large-literal RSS cost remain disclosed.

Fresh run_corpus.sh --both and MERE_RUBY_VM=1 run_corpus.sh --both each pass 1037/1037. All 96 strict comparisons, 25 unchanged original CRuby selected executions and 16 final source/native/record/whitespace checks pass. The description and completed loop record contain the full current-head evidence. No workflow or reference-gem changes; exact-head re-review and hosted CI remain pending.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed exact head 75671534c05c3368708fca4d17924c98a17c719c against fetched base 491cc5cab7e727606e1b00a141607e4742194d0a, with current main a56107b3e373b7bcb63c27f05d9142d1cbbd1d17 as context, including existing reviews/responses and the repair since 0cce4e80.

The two previous Major/P2 collision findings are fixed: literal construction uses digest buckets plus actual native key equality, and deletion requires the same key-equality rule before removing an entry. Both exact reproducers now match Ruby. The earlier overwrite-value-loss finding is also fixed: deferred values follow stable entry identifiers through key mutation, settlement, copies and deletion. Unique mutable buckets defer their value without publishing the entire pair list, ordinary frozen String keys retain indexed lookup, and index-off ordinary write membership again uses the independent walk. No new actionable findings.

Independent validation: 32 exact exit/stdout/stderr comparisons against clean Ruby 4.0.10 pass. Corpus 1139 and an additional collision/deletion/overwrite/copy/GC probe pass all eight evaluator/VM × Hash-index on/off × normal-GC/GC32 configurations; four related corpus files pass both engines and index modes. Nine source audits pass, including GC roots against freshly emitted C, method-write guards and bracket depth 155/1024.

Build reuse is explicit: all 2,837 tracked files match the recorded candidate build, and the three imported mgz sources are byte-identical to verified pinned 661a01d8bb68f5acd68e3192bd47f081d179c436. With clean pinned compiler 9dec2ff687a08433247dbdb7729bc19c8522e538, fresh C and FFI-header emission match that O2 build byte-for-byte. Reused interpreter SHA-256: ce1e42b3ae4c25757124543cbd252a3febf8b0fce66bb6daeff231fe6f0333bd; fresh C SHA-256: 61deb75a0520d618cc6c5f9e8f2bb5c8b3fc146cc579bc25d911b54a83c77e36. Native code was not recompiled.

The four repaired overwrite/read benchmarks at 4,000 and 8,000 keys pass their Ruby checksums on both engines, using tight GC and parsed seed 1. Single 8,000-key loop samples: Array-key overwrites 0.0160/0.0186 seconds (evaluator/VM), repeated first-key overwrites 0.0243/0.0197, mixed String overwrites 0.0158/0.0105, mixed String reads 0.0216/0.0247. These head-only, shared-machine samples support the code-path repair; they are not fresh paired baseline performance/RSS acceptance. The already disclosed small mutable-hash creation/copy and large-literal costs remain nonblocking follow-ups; pre-existing transform gaps are not claimed fixed.

I did not rerun full corpus, complete original CRuby files, framework components or affected-platform resource acceptance, nor test a prospective integration with newer main. No merge: the global hold_all_merges/new_failure_review_required remains active. PR Linux build is executing, macOS/reference jobs remain queued, and downstream acceptance is unfinished; this is outside the queue-only exception. The old main Module timeout and #395's additional hosted timeout remain preserved. COMMENT because the authenticated reviewer owns this PR. These specific code findings are cleared; global/platform gates are not.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed exact head 490d0106eba6cff472a829d255615f9e4e768ce9 against fetched base 8edcf953c37c3c7f0d4223c5227a7e4ea589ec6a, with latest fetched main 1cfbafeda5c0e8eb36af4ee4a979ca91ff2ea5b6 as context. Existing reviews, inline responses and the singleton-metadata follow-up were read. No new actionable findings.

The singleton path retains the insertion-time digest through overwrites, mutation, copies and promotion; entry vectors are deferred until growth. Copying tracked hashes also avoids building an index that would immediately be discarded. This directly addresses the earlier nonblocking small-hash creation/copy suggestion. The reported performance improvement is the author's measurement; I did not independently repeat its instruction/RSS comparisons. Previously disclosed large-literal memory costs and pre-existing transform gaps remain follow-ups.

Independent validation: 32/32 exact stdout/stderr/exit-status comparisons against clean Ruby 4.0.10 pass. Corpus 1139 and an additional singleton/collision probe cover evaluator/VM × index on/off × normal GC/GC32. The probe exercises Array and Hash keys, literal/assignment construction, overwrite then mutation, dup/clone/replace, promotion, deletion/reinsertion, rehash, collection, and the prior literal-collision and overwritten-value-loss reproducers. Four related corpus files pass both engines and index modes. Eight audits pass: duplicate/dead definitions, method-write generations, instance-variable doors, name specifications/length guards, GC roots, and emitted-C bracket depth (155/1024). An initial exploratory probe triggered CRuby's own small-table growth behavior and was corrected before comparison; it is not a PR finding.

Build reuse is explicit: all 1,825 recorded runtime/native/build inputs match the fresh fetched head, including imported mgz sources from pinned 661a01d8. With clean pinned Mere 9dec2ff6, freshly emitted C and the FFI header match the recorded O2 build byte-for-byte. Reused binary SHA-256: d715bcd0b8f0e979b1b7a28b73d3ee59766c5257977476f65c6a61d8111adde2; fresh C SHA-256: 518d162c8e599c9b1e53620ef91186e4dc66d2732670a1e75de0796a569ede63. Native code was not recompiled. I did not rerun the full corpus, complete original CRuby files, platform resource acceptance, or a prospective integration with newer main.

No merge: the recorded hold_all_merges / new_failure_review_required remains active. PR Linux build and several Linux suites are executing; macOS/reference work remains queued and downstream acceptance is incomplete. This is outside the queue-only exception. Latest main CI run 46149799893 has zero generated jobs, which does not clear the preserved original Module-check failure in run 46028215730 (195 tests, 0 failures, 1 error). The other open PRs (#392 and #245) are drafts; merelang/mere has no open PRs. COMMENT because the authenticated reviewer owns this PR.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed 75671534..490d0106 (a main merge, then "Defer per-entry Hash metadata for singleton mutable keys") against my remaining item.

Resolved. A one-entry mutable-key Hash now keeps only its saved native digest. Per-entry vectors and collision metadata are built when a second entry arrives, and promotion uses the insertion-time digest even if the key has changed since. A copy takes that saved association directly instead of building an index and discarding it. The small-case cost against main:

  • create: +44.7% → +2.2% (evaluator), +40.3% → +1.2% (VM);
  • create + dup: +84.8% → −2.0% (evaluator), +84.8% → −0.9% (VM);
  • the Symbol control is unchanged.

Corpus 1139 adds singleton overwrite/copy/GC, mutation before dup/clone/replace, promotion, historical collisions, deletion and reuse (96 strict comparisons in the author's record). The automated reviewer independently matched 32/32 against Ruby 4.0.10.

No further findings from me.

@284km
284km merged commit 08a452e into main Nov 28, 2026
11 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant