Repository navigation
Honor Hash conversion hooks in Array joins - #412
Conversation
284km
left a comment
There was a problem hiding this comment.
Reviewed exact head 5e5a093 against PR base 9d1c0f3 and current main 98aa453. No new actionable findings.
The Hash conversion path preserves to_str/to_ary/to_s precedence, checks conversion result types, and guards recursive conversions. The ordinary-Hash cache stores only integer facts and rechecks method generations; the regression coverage for callback redefinition and unrelated native aliases is useful.
Independent validation in isolated temporary checkouts:
- Fresh ordinary O2 builds of head and current main with local Mere v0.1.732 and mgz 661a01d8. Candidate SHA-256: 6ab9ff96e63c47307cb5a54751c23a909431835fd15211b5fbe22333eb9613e7. Main SHA-256: f7ff7b5ac130ad4d566700a22f76a79b8e259c80721e2e0f8d4ed3658128d18d. Both tracked trees remain clean; all 2,900 candidate repository/dependency file hashes remain unchanged across the final validation. Reference: clean Ruby 4.0.10 via tools/ref_ruby.sh; evaluator runs leave MERE_RUBY_VM unset.
- Corpus1164 matches Ruby on evaluator and VM, each under default settings, hash index disabled, GC stress=32, or method cache disabled (8/8). Existing corpus976/1009 match on both revisions in all eight configurations (32/32 comparisons). Main does not match the new fixture, as expected.
- An independent 43-case probe covers wrong/nil conversion results, private/native/inherited aliases, missing-method hooks, multiple Hash elements, callback changes to methods and array contents, recursion, GC, refinements, and anonymous included/prepended modules. Every configuration retains all five reference-matching main cases and increases that count to 42. The remaining array-shift case diverges on both revisions: Ruby raises EncodingError after the conversion mutates the leading array elements; candidate returns the joined shortened array. This is not a full conformance pass.
- The unchanged original ruby/test_array.rb, selecting test_join/test_join2/test_join_recheck_elements_type/test_join_recheck_array_length including inherited Array-subclass cases: 8 tests, 88 assertions, 0 failures/errors/skips on reference, main evaluator/VM, and candidate evaluator/VM.
- Generated-C/source StrBuf ownership, GC roots, duplicate/dead definitions, method writes, ivar door and diff whitespace checks pass.
I did not independently repeat the full corpus sweeps, performance measurements, sanitizer runs or platform/resource acceptance reported by the author. Hosted CI is incomplete: build-linux and gem suites are executing; build-macos, unittest-reference and additional coverage are queued. Latest main CI run46359889217 was inspected job by job: plan/harness/build-macos succeeded, build-linux is executing, and reference/corpus are queued; downstream completion is not established. No runner-queue exception or recorded global merge-hold clearance is claimed. This remains draft and is not merged.
284km
left a comment
There was a problem hiding this comment.
Reviewed head 5e5a093c (main.mere in Array#join's Hash arm, a generation-stamped cache in m_state.mere, corpus 1164, bench).
- A Hash element of
joinnow goes throughto_str, thento_ary(joined recursively with the same separator and the recursion guard), thento_s, as CRuby'sary_join_1does. Wrong return types raise the TypeError message Ruby gives. The top-level pre-pass also probes the first Hash'sto_str, matchingrb_ary_join's first loop. Corpus 1164 covers subclasses, singleton/aliased hooks,respond_to?arity andinclude_all,method_missing, wrong return types and recursion. - An ordinary Hash skips all probing via
plain_hash9. It checks thatHashitself defines none of the five hooks and caches the answer per MRO generation, so plain joins stay within ~+1%. - Cost note: a Hash subclass element costs +48% per join (59k → 88k instructions, evaluator), because it really has to be asked. That is required by the semantics and is in the body; fine.
No findings from me.
|
Investigated the intermittent Conclusion: the evidence supports runner-dependent throughput exposing pre-existing tight timeout headroom. There is no material local slowdown attributable to #408 or #412. The failing and passing CI evidence and actual headroomThese are case times from the uploaded
The green pre-change run had only 0.70 s / 7.0% and 1.14 s / 11.4% nominal headroom. The scheduled pass had 2.50 s / 25.0% and 3.16 s / 31.6%. Thus the marginal budget predates both changes. The failed runner was slower on the unrelated controls too: clone 1.56x, prepend_gc 1.69x versus the scheduled pass. Both Local comparison: median of three, both enginesSeparate clean source worktrees, each built with the exact CI-pinned Mere compiler commit above, mgz Ruby source/reference: No builds or profiling overlapped these benchmarks. Repetitions alternated commits (baseline→#408→#412, reverse, forward), sequentially. A parent-only
Across both changes and all four engine/workload combinations, median instructions stay within 0.14% of Where the leak loop spends timeSeparate diagnostic runs on
Three-second Proposed fixKeep the upstream 10-second child deadline, original iteration counts, and memory assertions. Target class-metadata construction and collection cost in a separate optimization: reuse owner classification within a collection across marking and the many That is an optimization proposal supported by these profiles, not an implemented or measured speedup. Require unchanged full Module acceptance (195 tests / 1,240 assertions / zero failures/errors/skips), both engines, unchanged memory bounds, and demonstrate at least 2 seconds of child headroom (target ≤8 s, median of three) on the slower Linux runner class before calling the flake repaired. Record CPU model/provider and CPU/pressure telemetry for that verification so hardware differences and contention can be separated. Retrying identical code can confirm runner variation but does not add headroom. No source/CI timeout change or revert of #408/#412 is warranted by this comparison. In particular, the two timed-out children were killed before completion: 10.05/10.04 s are censored durations, not evidence that a 10.1-second limit would suffice. No limit was raised. All three local samples (wall seconds / retired instructions in billions), in repetition order
Build provenance (local executable SHA-256):
Canonical child-input SHA-256 after replacing only upstream's two random tokens: iclass |
Array joins now ask Hash elements for
to_str, thento_ary, before falling back toto_s. Hash-subclass and singleton overrides participate in both the top-level string preflight and the actual join. Match Ruby's repeated conversion calls, private methods, native aliases, missing-method decline, TypeErrors for incorrect conversion results, and recursive conversion guards. Error messages use ordinary class names, including subclass results and singleton receivers.The existing Hash inspection/fallback and encoding behavior from #395 is preserved. Ordinary untagged Hash receivers use a protocol cache keyed by method generation with two integer slots and an integer tag lookup; they do not build an hng_key for each element. The cache is invalidated when methods change, including a callback defining a new conversion during the join, and unrelated classes' aliases do not disable it. It retains no anonymous owner or Ruby object.
Corpus 1164 covers string/array precedence, nil/wrong returns, private/singleton/native-alias methods, respond_to?/respond_to_missing?/method_missing, recursion, nested arrays, encoding, class-level hook addition/removal and callback redefinition. It matches ruby on both engines, including GC stress. Existing join controls 976 and 1009 match on both main and the candidate.
Original CRuby
ruby/test_array.rb, unchanged: test_join, test_join2, test_join_recheck_elements_type, test_join_recheck_array_length, including inherited Array-subclass cases: 8 tests, 88 assertions, 0 failures/errors/skips on reference, current main evaluator/VM and candidate evaluator/VM.Validation uses main 9d1c0f3, clean ruby 4.0.10 through
tools/ref_ruby.sh, pinned Mere 9dec2ff6 and mgz 661a01d8, ordinary O2. Candidate SHA-256:2f9c210d9c667b1bfed40b797834533a0c526a2d2586d653ace9c6ccf271d1d3. Runtime input hashes are verified before and after runs; evaluator runs leaveMERE_RUBY_VMunset.sh run_corpus.sh --both: 1040/1040 PASS, index on/off.MERE_RUBY_VM=1 sh run_corpus.sh --both: 1040/1040 PASS, index on/off.MERE_RUBY_VM=1 sh tools/iseq/vm_corpus.sh -j 2: 1040 on the VM, 0 fallback, 0 FAIL.bench/hash_join_conversions.rb MODE 10000 --seed=1versus the same mode with count 0, on the same pinned binaries. Each engine usesMERE_RUBY_GC_TIGHT=1and three alternating main/candidate pairs. Per-call instructions are(median I(10000) - median I(0)) / 10000, including loop dispatch; RSS is the maximum of the three count-10000 runs, in MiB. These measurements include the loop and use the workload committed in this PR.The subclass workload deliberately defines to_str and to_s with the same output: main skips the required to_str calls, while the candidate performs Ruby's preflight and actual conversion. Its extra dispatch cost is reported rather than treated as an equivalent path without conversion overrides. plain_alias defines a native alias only on an unrelated Hash subclass; ordinary Hash joins stay on their ordinary path. No collector or arena-policy changes are included.
Local validation is complete; exact-head review and hosted CI remain. No runner-queue exception or merge-hold waiver is claimed.