Skip to content

Preserve Array override arguments until native index conversion - #406

Merged
284km merged 8 commits into
mainfrom
codex-rails1-array-index-integer-fast
Nov 28, 2026
Merged

284km merged 8 commits into
mainfrom
codex-rails1-array-index-integer-fast

Conversation

@284km

@284km 284km commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Array subclass overrides received arguments after native index conversion, so Mail::AttachmentsList#[]= rejected filename String keys before its Ruby body ran. Preserve original arguments for Ruby overrides, and apply conversion on native alias, retained Method and super entry. Native entry checks Array's original arity before any conversion hook.

Arguments that need no conversion skip the added override probe: exact Integer shapes, zero arguments, three-Integer values_at, and integer/nil-bound Range slicing. Corpus941 includes filename keys, assignment returns, frozen override bodies, native conversion, original to_int-bearing objects, and wrong-arity nil/side-effecting-to_int calls through aliases, Methods and super.

Final measured standalone runtime da465c1481770a472764455c775bacea047528c0, main control 8edcf953c37c3c7f0d4223c5227a7e4ea589ec6a; clean Ruby4.0.10 through tools/ref_ruby.sh, revisiona704b7cd95, Prism1.8.2, zero extra gems. Compiler9dec2ff6, mgz661a01d8. Publication adds records to this tested code.

  • run_corpus.sh --both: 1036/1036, hash index ON/OFF. VM: 1036 VM / 0 fallback / 0 differences.
  • Corpus941 matches all8 evaluator/VM × hash-index × normal-GC/GC32 configurations.
  • Source gates, supplemental StrBuf, default/explicit record hygiene and diff checks pass.
  • Related Array36-case selection: all five sides COMPLETE. Both Mere controls retain the same2 pre-existing range-with-max-length failures; no previous main PASS lost.
  • Earlier whole test_array observations at425 remain explicit in the original record: reference493tests/23683assertions all passing; both Mere controls/engines MEMORY_LIMIT in permutation-array-modified, including isolated replays. That incomplete whole file was not rerun or relabeled passing in this follow-up.

Net instructions per operation including the loop, three alternating pairs against main8ed. Ordinary rows use0-versus20000 iterations; Range/values_at use0-versus100000. Every output matches the reference.

Operation evaluator VM
plain_array_read -2.17% -0.69%
plain_array_write -1.78% -1.10%
plain_array_fetch -1.56% -1.31%
array_range_slice -1.26% -1.41%
array_values_at_three_ints -2.81% -2.69%

Large-file max RSS, exact standalone main8ed→finalda465c14: AS JSON encoding158MATCH in all12 runs, all COMPLETE/all passing. Fresh native gems installed by each exact measured binary and recovered reference; seed12345, normal GC, jobs2,600s/2GiB per file family, three alternating pairs.

Engine Before samples KiB After samples KiB Median change
evaluator 1611200 / 1589248 / 1625328 1616144 / 1587952 / 1572800 -1.44%
vm 1153392 / 1363952 / 1110960 1108720 / 1195424 / 1181248 +2.42%

All samples and variation are retained; no stable memory improvement is inferred from overlapping ranges. The original pre-optimization cost/RSS observations also remain available.

Final separate Action Mailer integration 2e4f119295a5afe87cc8a8eaaef03ea8cbeea35b: all17 files, evaluator268MATCH/0other and VM268MATCH/0other; both sides COMPLETE for every file, no time/memory bounds. Prior full cohort248MATCH/20RED→268MATCH/0RED. Base102MATCH and message_delivery25MATCH both engines. This integration includes the merged ActiveJob395, class-reflection399, parser402 and keyword405 prerequisites plus this Array correction; it is not the standalone PR binary or later current main. Integration corpus1037/1037, VM1037/0/0. Full per-file states, times and source/native receipts are in actionmailer-final-17.json and the completion report.

The prior reference prefix developed missing RubyGems files; v15 stopped before discovery and remains an environment failure. Final controls use a new isolated official Ruby4.0.10 build, identical revision/Prism1.8.2/46-default-spec inventory, strict extra-gem guard passed, new binary SHA256 3d4b6667beb1612cc7076ae14e2a9f299d4fc870cb75b22371ab6ba6f2e7d5c8. All final native installs are fresh; no Gem.default_dir writes.

Evidence: loop/2026-11-29-codex-rails1-array-index-review-followup.md, railstest/framework/records/actionmailer-array-index-review-followup.json, actionmailer-final-17.json, and the original actionmailer-array-index-overrides.json.

Measured source pins predate #373's read helpers. Current-main StrBuf findings there are with that stream; no gate suppression or current-main/hosted-CI pass is claimed. Code and records are batched in one push. Exact-head automated review and owner acceptance remain required; no self-merge.

@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 head 5521d70b (main.mere +22/-4, corpus 941, record).

  • Semantics: right. A Ruby override of an Array index method, on the singleton or on an Array subclass, now receives the original arguments, as in Ruby. Mail::AttachmentsList#[]= with a filename String key reaches its body. Native entry through an alias (blt_alias_call), a retained Method or super still converts with coerce_arr_index_args, so super(name) from such an override keeps Array's own conversion and errors. Corpus 941 covers both sides, including a to_int that must not run before the override.
  • Fast path: exact Integer arguments skip both the conversion and the new override lookup. The read/write/fetch rows are flat or slightly faster.

[Minor] Please measure the non-Integer path too. Every call whose arguments are not the listed Integer shapes now does has_meth (dispatch_cls_of recv) name plus hng_sng_has before converting. That covers a[1..3], a[-2..], a[i, n] with a non-Integer n, a.values_at(...), a.flatten(1), a.rotate(k) with a Float, and a.slice(range). Range slicing is common in real code, so please add a row for a[1..3] (and values_at with 3 Integers, which misses the 1–2 argument fast shapes) against main on both engines. If it is measurably slower, the 0- and 1-argument Range shapes could join the fast path: a plain VRange of Integers on a receiver whose class is exactly Array with no singleton.

The merge waits for that row and for the automated reviewer on the head.

@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 5521d70be656dd44261dc8c0915f45cf845a5115 against current main 08a452ebb2f563b15ca9caaae83dd44c2ad3ebaa.

The original-argument dispatch change is supported by corpus 941: it matches clean Ruby 4.0.10 in all eight evaluator/VM × hash-index ON/OFF × normal-GC/GC32 configurations. I found one additional Minor correctness regression in native-alias arity handling, detailed inline. The existing review's non-Integer performance request is still outstanding and is not duplicated here.

Validation: separate temporary checkouts and fresh ordinary O2 builds of head and current main, mgz 661a01d8; regenerated head C matches the published pinned-compiler C SHA256 (b9202849…). The alias-arity reproducer matches Ruby on main in 8/8 configurations and differs on this head in 8/8. Source name-length, method-write, GC-root and StrBuf checks, changed-record hygiene and diff whitespace checks pass on the head. Full corpus, whole upstream Array tests and framework/resource comparisons were not rerun in this review; the publication's incomplete Array observations remain incomplete. Exploratory fetch/super and ArithmeticSequence alias discrepancies also occur on main and are excluded from the findings.

No merge: the recorded all-merge hold remains active, and hosted CI still includes running tests/builds and queued jobs, not only unassigned runner queues. Latest main CI run 46151473357 has an actual Linux source-gate failure in the pre-existing read_path_whole/read_path_at StrBuf helpers; that is not attributed to this Array change. The other open PRs are drafts; there are no eligible already-reviewed candidates.

Comment thread main.mere Resolved
@284km

284km commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner Author

The final17-file Mailer sweep stopped before test discovery: the previously clean private Ruby4.0.10 can no longer boot RubyGems because kernel_require.rb is missing. Its binary still has the original5ad9092c SHA and a704b7cd revision, but default gem specifications and parts of its source tree are also absent. No Rails test ran and no results.json was produced; this is preserved as an environment-startup failure, not a framework RED or an all-pass result. Cause is not yet established.

I am rebuilding an independent reference from the official Ruby4.0.10 release, SHA-256 b53eef3371fa5d3e3b74340edcd015f06d5d8853968d4e539a5264fce41ed9f1 (matches the installed ruby-build definition), revisiona704b7cd95. Before resuming I will require exact agreement with the earlier inspected inventory (46 default specifications; no nondefault specifications), Prism1.8.2 and zero extras, then use fresh native installation/output directories. The code and previously completed measured-source records are unchanged. The failed attempt and new-reference provenance will stay distinct in the final report; no record-only push is planned.

Correction to the initial inventory count: the preserved isolated reference-inspection receipt contains46 default specs, not84. The rebuilt reference was compared for exact equality with that receipt, in addition to the strict extra-gem guard. The new full17-file cohort is now complete and reported below.

@284km

284km commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner Author

The full Action Mailer run is finished; this stream has released its full-component slot.

Both engines: 268 MATCH, 0 RED/MISSING/BOTH/UNCONFIRMED/EXTRA. All17 files are COMPLETE on both reference and Mere; no bounded file needed an isolated rerun. The earlier full cohort had248MATCH/20RED.

This is the frozen local integration including the PR406 review corrections (native alias arity and Range/three-Integer no-coercion paths), not a claim about later current-main changes. Standalone PR runtime da465c14: corpus --both1036/1036 and VM1036/0fallback/0differences; integration runtime has1037/1037 and VM1037/0/0. Source gates, StrBuf and the COMPLETE related36-case Array selection pass their expected controls; both Mere controls retain the same2 pre-existing range-length failures, with no lost previous PASS.

The PR406 code/record follow-up is still local while its final large-file RSS comparison runs. I will batch those commits into one push, then request exact-head re-review. The original reviewed head remains unchanged for now.

actionmailer integration measurement

All 17 selected files measured against clean Ruby 4.0.10 through tools/ref_ruby.sh.
Runtime 2e4f119295a5afe87cc8a8eaaef03ea8cbeea35b, integration main base 8edcf953.
Fresh native installation for each measured interpreter.

Mode MATCH RED MISSING BOTH UNCONFIRMED EXTRA
evaluator 268 0 0 0 0 0
vm 268 0 0 0 0 0

Per-side file states:

Mode / side COMPLETE ZERO INCOMPLETE COUNT_MISMATCH REPORT_MISMATCH MEMORY_LIMIT WALL_LIMIT ABSENT
evaluator / reference 17 0 0 0 0 0 0 0
evaluator / mere 17 0 0 0 0 0 0 0
vm / reference 17 0 0 0 0 0 0 0
vm / mere 17 0 0 0 0 0 0 0
Mode Start UTC End UTC
evaluator 2026-11-28T16:12:45.533627+00:00 2026-11-28T16:14:14.935057+00:00
vm 2026-11-28T16:14:16.547757+00:00 2026-11-28T16:15:38.195153+00:00

Remaining REDs by file:

Bounded files requiring isolated reruns: 0.

File E reference E mere VM reference VM mere E MATCH/RED VM MATCH/RED
actionmailer/test/assert_select_email_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 2/0 2/0
actionmailer/test/asset_host_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 2/0 2/0
actionmailer/test/base_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 102/0 102/0
actionmailer/test/caching_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 19/0 19/0
actionmailer/test/callbacks_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 7/0 7/0
actionmailer/test/delivery_methods_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 21/0 21/0
actionmailer/test/form_builder_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 1/0 1/0
actionmailer/test/i18n_with_controller_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 1/0 1/0
actionmailer/test/log_subscriber_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 3/0 3/0
actionmailer/test/mail_helper_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 9/0 9/0
actionmailer/test/mail_layout_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 7/0 7/0
actionmailer/test/message_delivery_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 25/0 25/0
actionmailer/test/parameterized_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 5/0 5/0
actionmailer/test/structured_event_subscriber_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 3/0 3/0
actionmailer/test/test_case_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 5/0 5/0
actionmailer/test/test_helper_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 54/0 54/0
actionmailer/test/url_test.rb COMPLETE COMPLETE COMPLETE COMPLETE 2/0 2/0

Qualifications:

  • This integration combines current main8edcf953 with the reviewed ActiveJob/class-
    reflection/setter-symbol changes and the Array-index dispatch, marked forwarding
    keywords and Range cost follow-ups. Prior d1ce Mailer results are a separate cohort;
    current-main runtime and CAPI changes are included. Each binary has its own fresh native
    installation.
  • A complete file is not necessarily all passing. Remaining REDs and every non-COMPLETE
    state are retained explicitly.
  • Only this exact frozen integration is measured. Native extensions were freshly
    installed by this measured binary; no prior native install reuse.
  • Per-file family bounds are 600 seconds and 2 GiB, jobs 2, fixed seed 12345. Full
    component runs are serial across this stream; all work used the shared two-slot Codex
    admission gate.
  • This full Mailer cohort uses only the opaque-class-addresses identity policy. The
    separate large-JSON resource controls use rails-argument-descriptions. Raw inventories
    and actual policy fields are retained; every assertion runs unchanged.
  • External residuals remain in the raw counts and strict all_pass result; explicit
    predecessor policies allow only named cases linked to their issues. They do not mark
    those cases passing.
  • This cohort also includes the Array alias-arity and Range/three-Integer fast-path
    review corrections from PR406. It uses a separate new integration binary and a new
    native installation.
  • The previous v15 attempt failed in reference RubyGems startup before any Rails file
    discovery or test execution. That environmental failure remains preserved separately; it
    is not included as a test failure or a passing run.
  • The isolated reference was rebuilt from the official Ruby4.0.10 release archive after
    missing RubyGems files were detected. Version, revision, Prism1.8.2 and the
    exact46-default-gem inventory match the former inspected reference; the rebuilt binary
    has its own SHA256 and every native gem for this cohort was freshly installed with it.

Reference selector: tools/ref_ruby.sh, Ruby4.0.10 revision a704b7cd95a42cc0cf5f307137bf3aac0285b915, Prism1.8.2, strict extra-gem guard passed. Rebuilt reference binary SHA256 3d4b6667beb1612cc7076ae14e2a9f299d4fc870cb75b22371ab6ba6f2e7d5c8 from verified official release archive SHA256 b53eef3371fa5d3e3b74340edcd015f06d5d8853968d4e539a5264fce41ed9f1. The prior reference prefix had missing RubyGems files; v15 stopped before discovery, and its failure is retained separately. This v16 cohort uses a completely new native install made by runtime 2e4f119295a5afe87cc8a8eaaef03ea8cbeea35b (binary SHA256 4739619adc2303a49dc492187b99248af1e71244db23bb7b4a1705f9cf29c88d) and this rebuilt reference, tooling 5128773a67a26c94a35585774525192f0653f2ec. No reference gems were installed into Gem.default_dir.

@284km

284km commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

Pushed the two review corrections and their records together, once. Exact new head: 8483ecb40947e1243d40ceaac7a779f62bff1d06; measured runtime da465c1481770a472764455c775bacea047528c0 plus record-only publication.

  • Native alias arity now precedes coercion, with nil/to_int side-effect cases in corpus941, matching all8 configurations.
  • The requested non-Integer measurements initially showed a3–5% cost. No-conversion paths remove it: Range slice evaluator−1.26%/VM−1.41%; three-Integer values_at evaluator−2.81%/VM−2.70%, three alternating100k pairs against main8ed. Ordinary read/write/fetch medians also improve; all raw samples are retained.
  • Corpus --both1036/1036; VM1036/0/0; gates/StrBuf/explicit record hygiene clean. Related36-case Array selection COMPLETE on all five sides, same2 baseline failures, no lost PASS.
  • Final standalone large-file RSS uses completely fresh native installs for each measured binary and recovered reference. AS JSON158MATCH in all12 runs, all COMPLETE. Evaluator median−1.44%, VM+2.42%; overlapping sample ranges, no stable-memory-improvement claim.
  • Full separate integration: evaluator268MATCH/0other and VM268MATCH/0other, all17 files COMPLETE, no bounds. Full per-file report. The full-component slot is released.

Review/resource evidence and full17-file record. Original whole-Array bounded observations and pre-optimization measurements remain explicitly separate.

The PR remains Ready for re-review. Exact-head bot review and owner acceptance are still required; the global merge hold is not inferred to be lifted, and no self-merge is performed. Current-main373 StrBuf findings remain with that stream.

@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 5521d70b..8483ecb4 against my Minor and the automated one.

  1. Non-Integer path cost: addressed. Zero arguments, three-Integer values_at, and Integer/nil-bounded Range slicing ([], slice, slice!, values_at) now skip the override probe. Since those arguments need no conversion, passing them through unchanged is correct whether or not an override exists. The new rows are a[1..3] −1.3%/−1.4% and values_at with 3 Integers −2.8%/−2.7% against main.
  2. Alias/super arity before coercion: addressed. array_index_native_call checks Array's native arity from arity_tbl before coerce_arr_index_args. Corpus 941 adds wrong-arity calls through aliases, Methods and super with a nil index and a side-effecting to_int.

Suggestion (non-blocking): in array_index_native_call, the arity failure is let _ = raise_exc ... in (), and the function then falls through to prim_method recv name (coerce_arr_index_args ...). Elsewhere raise_exc only records the exception. The corpus shows the to_int hook does not run, so presumably the pending exception stops the conversion further down. Still, an explicit if bad then raise_exc ... else prim_method ... would make "reject before converting" local rather than dependent on that.

No blocking findings from me. The merge waits for the automated reviewer on this head.

@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 8483ecb40947e1243d40ceaac7a779f62bff1d06 against current main 08a452ebb2f563b15ca9caaae83dd44c2ad3ebaa, including the existing reviews and follow-up discussion. No new actionable findings.

The previous Minor native-alias arity finding is fixed. Wrong-arity at/flatten calls through saved aliases, retained Methods and super now raise ArgumentError before nil/index conversion; the side-effecting to_int counter stays zero. Corpus 941 and an independent arity/Range probe each match clean Ruby 4.0.10 in all eight evaluator/VM × hash-index ON/OFF × normal-GC/GC32 configurations. The original alias/retained-Method control also matches Ruby on both current main and this head in all eight configurations. raise_exc ends in fail, so the error path exits before reaching coercion; this does not rely on a pending-exception flag.

The non-Integer performance request is addressed by the unchanged-argument Range and three-Integer values_at paths. I recomputed the published medians from their raw instruction samples and checked their source pins; I did not independently rerun those performance measurements. The 17-file Mailer record contains matching reference/Mere PASS inventories for all 268 identities in both engines. Those are the documented frozen integration results, not a new current-main integration run. The two recorded Array baseline failures and earlier incomplete whole-Array memory-bound observations remain explicit.

Validation used separate temporary checkouts and fresh ordinary O2 builds. Compiler 9dec2ff6 was freshly built; its head-generated C matches the recorded SHA256 9bee678203974d273325ccd76e77f6a1f70d32716413cafb8771810335ab1404, and the FFI header agrees. mgz is pinned at 661a01d8. Reference Ruby is 4.0.10, revision a704b7cd95, Prism 1.8.2, with the reference extra-gem guard passing. Head name-length, method-write, GC-root, StrBuf, changed-record hygiene and diff whitespace checks pass. Full corpus, whole upstream Array and framework/resource suites were not rerun in this review.

No merge: hold_all_merges and new_failure_review_required remain active. Hosted CI still has running builds/tests plus queued jobs, so the unassigned-runner-only exception does not apply. Every job of latest main CI run 46151473357 was inspected: Linux build and corpus actually fail the existing read_path_whole/read_path_at StrBuf gate; the same gate failure reproduces on current main locally and is not introduced by this PR. The other open mere-ruby PRs (#392 and #245) are drafts; merelang/mere has no open candidates.

@284km
284km merged commit 5b815b6 into main Nov 28, 2026
24 of 37 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