Skip to content

perf(objects): copy small Source contents out of the shared inflate buffer - #10785

Merged
davidfirst merged 3 commits into
masterfrom
perf-source-contents-copy
Oct 9, 2026
Merged

davidfirst merged 3 commits into
masterfrom
perf-source-contents-copy

Conversation

@davidfirst

Copy link
Copy Markdown
Member

zlib.inflate returns results smaller than its 16KB chunk as a slice of a 16KB buffer. Source.parse kept that slice, so every small file loaded from the scope held 16KB. bit status in this repo loads ~3.2k head-version files (~11MB of content) that held ~55MB.

Source.parse now copies the contents when they use less than half of the underlying buffer (small copies come from Node's shared pool). On bit status, external/buffer memory dropped from ~105MB to ~62MB.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Reduce memory retained by small parsed Source objects

✨ Enhancement 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Copy small Source contents so they do not retain an oversized inflate buffer.
• Preserve larger buffers to avoid unnecessary copies.
• Test content, hash, and backing-buffer size after parsing a compressed Source.
Diagram

graph TD
  A["Compressed Source"] --> B["Inflate object"] --> C{"Small slice?"} -->|Yes| D["Copy contents"] --> F["Retained Source"]
  C -->|No| E["Reuse contents"] --> F
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Always copy parsed Source contents
  • ➕ Simpler rule that never retains the inflate backing buffer.
  • ➖ Copies large files unnecessarily, increasing allocation and CPU costs.

Recommendation: Keep the conditional copy: it addresses retention for small files without imposing a copy on larger ones.

Files changed (2) +17 / -0

Enhancement (1) +3 / -0
source.tsCopy small contents during Source parsing +3/-0

Copy small contents during Source parsing

• Source.parse copies contents when they occupy less than half their backing buffer, preventing a small file from retaining a much larger inflate buffer. Larger contents continue to use the original Buffer.

scopes/scope/objects/models/source.ts

Tests (1) +14 / -0
source.spec.tsTest small Source backing-buffer retention +14/-0

Test small Source backing-buffer retention

• Adds a compressed-object parse test that verifies the Source content and hash remain unchanged while its backing buffer is smaller than 16 KB.

scopes/scope/objects/models/source.spec.ts

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can show, collapse, or hide each part of a finding: code, evidence, and all

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous reviews

Review updated until commit 96b49c7 🚀 Fast

Results up to commit 197454b


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Qodo Logo

@davidfirst
davidfirst enabled auto-merge (squash) October 9, 2026 15:24
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 96b49c7

@davidfirst
davidfirst merged commit aae2e0a into master Oct 9, 2026
14 checks passed
@davidfirst
davidfirst deleted the perf-source-contents-copy branch October 9, 2026 23:49
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