fix: Use in-place append for buffer concatenation to fix O(n^2) performance#80
Merged
fix: Use in-place append for buffer concatenation to fix O(n^2) performance#80
Conversation
…rmance The previous change (0e2e80d) replaced `buffer << chunk` with `buffer += chunk` to handle frozen strings. However, `+=` creates a new string on every iteration, resulting in O(n^2) behavior for large payloads. The buffer is already explicitly unfrozen (`+"".b`), so `<<` is safe to use. This restores the in-place append while keeping the `.dup` on the incoming chunk to avoid mutating frozen caller strings.
jsonbailey
approved these changes
Mar 2, 2026
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Replace `buffer = ""` with `buffer = +"".b` so the reset buffer remains unfrozen and binary-encoded, matching the initial assignment. Without this, `buffer << chunk` after the reset would raise a FrozenError in Ruby 3.4+ where string literals are frozen by default. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
keelerm84
pushed a commit
that referenced
this pull request
Mar 2, 2026
🤖 I have created a release *beep* *boop* --- ## [2.5.1](2.5.0...2.5.1) (2026-03-02) ### Bug Fixes * Use in-place append for buffer concatenation to fix O(n^2) performance ([#80](#80)) ([a7e6c23](a7e6c23)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The previous change (0e2e80d) replaced
buffer << chunkwithbuffer += chunkto handle frozen strings. However,+=creates a newstring on every iteration, resulting in O(n^2) behavior for large
payloads. The buffer is already explicitly unfrozen (
+"".b), so<<is safe to use. This restores the in-place append while keeping the
.dupon the incoming chunk to avoid mutating frozen caller strings.Note
Low Risk
Low risk: small, localized change to streaming buffer concatenation; main concern is any subtle string mutability/encoding edge cases during line parsing.
Overview
Restores in-place buffer growth in
BufferedLineReader.lines_fromby switching frombuffer += chunkback tobuffer << chunk, avoiding per-chunk string allocations and O(n^2) behavior on large streams.Also ensures the buffer reset path reinitializes to an unfrozen binary string (
+"".b) rather than a potentially frozen empty literal.Written by Cursor Bugbot for commit 37d5f65. This will update automatically on new commits. Configure here.