Skip to content

Shared: stream TRAP output in the tree-sitter extractor writer - #23331

Open
redsun82 wants to merge 2 commits into
mainfrom
redsun82-special-couscous
Open

redsun82 wants to merge 2 commits into
mainfrom
redsun82-special-couscous

Conversation

@redsun82

@redsun82 redsun82 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: d4a55d1d80e9e3658e9045e4e7894d2d169c4ed3

Dimension Assessment Rationale
Change confidence 9/10 ↑ Decompressed TRAP is byte-identical before/after for Ruby (11.5k + 340 test files), QL (17k files) and Rust ripgrep source files.
↑ Ruby ast/controlflow QL tests (29/29) and ql/ql/test (57/57) pass with the new extractors; extractor cargo tests pass.
↓ Unified extractor only type-checked (no Swift toolchain locally); CI pending.

trap::Writer used to buffer owned Entry values and format them only when writing the file. It now formats each entry straight into a Vec<u8> as it is added, which avoids the per-entry allocations and keeps peak memory lower. This benefits every extractor using the shared crate (Rust, Ruby, QL, unified).

Output is unchanged. The now-unused Entry, Program and Display for Arg are removed, and comment takes &str. add_tuple keeps its signature, so generated code is untouched.

Rough local measurements (user+sys CPU, before -> after):

Extractor CPU Peak RSS
Rust, ripgrep (whole index-files) -10% ~same
Ruby, 11.5k files -17% 173 -> 116 MB
QL, 17k files -26% 1.7 -> 0.7 GB

Format TRAP entries straight into a byte buffer instead of buffering
owned `Entry` values and formatting them at write time. Output is
unchanged. Drop the now unused `Entry`, `Program` and `Display for Arg`,
and take `comment` text by reference.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ab88cf13c49431ab5be915077ce518e
@redsun82
redsun82 requested a review from a team as a code owner December 2, 2026 14:02
Copilot AI adaptive review requested due to automatic review settings December 2, 2026 14:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the TRAP writer memory-efficiency changes.

No open issues 🎉

What changed in this PR

This PR reduces allocation and memory overhead in the shared TRAP writer used by Rust, Ruby, QL, and unified extractors while preserving output formatting.

Changes:

  • Formats entries directly into a byte buffer and removes unused intermediate types.
  • Changes comment to accept borrowed strings and updates callers.
  • Adds tests for output formatting and UTF-8 string truncation.
File Description
shared/​tree-sitter-extractor/​src/​trap.rs Implements byte-buffer formatting and adds regression tests.
shared/​tree-sitter-extractor/​src/​extractor/​mod.rs Updates extraction callers for borrowed comments.
shared/​tree-sitter-extractor/​src/​extractor/​driver.rs Updates test callers for borrowed comments.

Review effort: Balanced (adaptive)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the TRAP writer’s switch to direct byte-buffer formatting.

No open issues 🎉

Review effort: Balanced (adaptive)

This branch has not been deployed

No deployments
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