Skip to content

Avoid allocating source lines when counting - #860

Closed
OskarEichler wants to merge 1 commit into
rails:mainfrom
OskarEichler:codex/source-map-line-count-allocation
Closed

Avoid allocating source lines when counting#860
OskarEichler wants to merge 1 commit into
rails:mainfrom
OskarEichler:codex/source-map-line-count-allocation

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Count source lines without allocating an array and one string per line.

ASCII-compatible strings use a byte-count fast path. Non-ASCII-compatible encodings retain each_line semantics, preserving UTF-16/UTF-32 behavior.

Evidence

For 100,000-line UTF-8 source, measured allocations fall from 100,002 to 1. Alternating local samples on Ruby 4.0.6 and 3.2.11 were approximately 12–16 times faster. This is a focused microbenchmark, not an application-throughput claim.

Verification

  • Exact line-count parity covers empty, final/non-final newline, CRLF, invalid-byte, binary, UTF-8, UTF-16LE/BE and UTF-32LE/BE inputs on both Rubies.
  • Release/current baseline and combined completion candidate: unchanged suite passes 913 tests / 4,109 assertions / 0 failures / 0 errors / 4 skips on Ruby 4.0.6 and 3.2.11.
  • Full RuboCop checks 133 files with zero offenses; syntax, package parity and isolated package load pass.

Compatibility

Returned data and source-map line-count semantics are unchanged. No dependency/version change. Existing tests were not edited under the consumer repository’s no-test-edit policy; focused evidence ran externally. Prepared with AI assistance.

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.

2 participants