Skip to content

Release temporary buffers in path-based reads - #411

Closed
284km wants to merge 2 commits into
mainfrom
codex-rails1-file-read-buffer-regions
Closed

284km wants to merge 2 commits into
mainfrom
codex-rails1-file-read-buffer-regions

Conversation

@284km

@284km 284km commented Nov 30, 2026

Copy link
Copy Markdown
Owner

The path-read helpers introduced in #373 allocate StrBuf scratch buffers in the default region. Current main fails the existing region gate in both source and generated C (4 findings). Put each buffer in a dedicated region and return only the completed bytes. The regular-sized read_file fast path is unchanged.

Corpus 1027 retains results from bounded file reads, a pipe and a device through arena reuse and collection. No gate allowances or framework expectations change.

Local validation, runtime 829cef2256695c3f3f300b0f7268e283517e3a6b against main 5b815b660e9e:

  • run_corpus.sh --both: 1040/1040, hash index on/off.
  • VM corpus: 1040 VM / 0 fallback / 0 differences.
  • All source gates and default/explicit record hygiene pass. StrBuf source/emitted-C gate: 4 findings → 0.
  • Four read programs across both engines, hash on/off and GC-stress32: 32 candidate observations match; main and reference controls also match.
  • Official test_io selection: 7 tests / 32 assertions, zero failures/errors/skips on clean Ruby, main and candidate in both engines; all COMPLETE. This is a selection, not the whole file.
  • AS JSON encoding: 158 MATCH / 0 RED, other categories zero and all COMPLETE in all 12 before/after runs. Seed12345, jobs2, normal GC, 600s/2GiB family bounds. Fresh native gems for each exact binary.

Peak RSS (KiB), three alternating large-file pairs:

Engine Before samples After samples Median change
evaluator 1464800,1454752,1509328 1572800,1569104,1448256 +7.12%
VM 1285184,1262752,1206528 1312640,1255120,1337968 +3.95%

The ranges overlap; these higher medians are not presented as a Rails memory improvement. The repeated 128×1MiB read control shows scratch-buffer RSS medians 161952→103456 KiB (evaluator), 164944→102000 KiB (VM). Net instructions/read including loop and explicit GC rise about 0.44%/0.90% respectively; the lifetime fix is needed for correctness of region ownership and the existing gate.

Reference: tools/ref_ruby.sh, clean Ruby4.0.10 revision a704b7cd95a42cc0cf5f307137bf3aac0285b915, Prism1.8.2, 46 default specs, no extras. Compiler 9dec2ff687a0, mgz 661a01d8bb68. Full portable evidence: railstest/framework/records/path-read-buffer-regions.json; loop note included.

Owner merge remains pending exact-head automated review.

@284km

284km commented Nov 30, 2026

Copy link
Copy Markdown
Owner Author

Superseded by already-merged #409 (main 9d1c0f3). I discovered that merge while preparing this independent follow-up; keeping a second implementation would duplicate the same correction. Closing this PR without merge. The retained evidence describes runtime 829cef2 against 5b815b6, not the exact #409/main binary. Subsequent integration measurements will use main’s implementation.

@284km 284km closed this Nov 30, 2026
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