Skip to content

Stop re-parsing bun lock entries for every patch in scan (#580) - #1051

Queued
Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
arch-refactor/580-bun-bundled-check-hoist
Queued

Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
arch-refactor/580-bun-bundled-check-hoist

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes the bun scan slowdown reported on #580. The hosted and vendored bun paths were re-parsing each lock entry's JSON on every (patch, entry) pair.

Why

The maintainer asked on #580 whether the bun regression came from a bug fix or from wasted work. It is mostly wasted work that came in with a real fix. The slowdown was bisected to #472 (1169ae6), which correctly stopped rewriting Bun {"bundled": true} entries. The fix is legitimate, but it ran is_bundled_entry, a full serde_json parse of the entry's meta object, before the cheap spec comparison. That parse ran once per (patch, entry) pair: about 3,000 entries × 127 patches ≈ 380k JSON parses per scan. bun/hosted went from 144 to 302 ms; the request count was unchanged, so the cost is all CPU.

Change

  • rewrite_bun_lock (redirect/mod.rs): decode each entry's spec once per lock and compare it first. The bundled flag is computed lazily, and cached per entry, only for entries whose spec matches a patch.
  • classify_rewritable / bundled_matches (vendor/bun_lock.rs): classify first, and parse meta only for entries that match.
  • is_bundled_entry (bun_lock_text.rs): fast path that skips the JSON parse when the meta never spells bundled and contains no backslash, so an escaped key still goes through the parse. Malformed meta that mentions bundled still fails closed.

The behavior from #472 is kept: bundled entries are still skipped, warned about and left out of VEX.

Results

Refs #578, #580. The bench tracking issue stays open.

🤖 Generated with Claude Code


Note

Low Risk
Behavior-preserving performance refactor with regression tests; bundled skip/warn/VEX rules unchanged from #472.

Overview
Fixes #580 bun scan slowdown by avoiding redundant work on every patch×lock-entry pair while keeping #472 bundled-entry skip semantics.

rewrite_bun_lock now decodes each entry’s spec once per lock and caches whether an entry is bundled only after a cheap spec match, instead of JSON-parsing meta on every patch loop. Vendoring (classify_rewritable, bundled_matches) uses the same order: classify first, then is_bundled_entry. is_bundled_entry adds a substring fast path that skips serde_json when the meta cannot contain a bundled key (still parsing when a backslash might hide an escaped key).

New tests lock in that bundled warnings/VEX skipping apply only to matching specs, and that the fast path matches the full parse.

Reviewed by Cursor Bugbot for commit fe5a42a. Configure here.


Generated by Claude Code

…write

rewrite_bun_lock ran is_bundled_entry, a full serde_json parse of each
entry's meta object, before the cheap spec comparison, once per
(patch, entry) pair. On the bench fixture (about 3,000 entries x 127
patches) that is roughly 380k JSON parses per scan, which doubled
bun/hosted and bun/rescan after #472 (144 -> 302 ms).

Decode each entry's spec once per lock, compare it first, and compute
the bundled flag lazily (cached per entry) only for entries whose spec
matches a patch. Bundled entries are still skipped, warned about and
kept out of VEX.

Refs #578, #580

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
classify_rewritable and bundled_matches now run classify first and
only parse the meta of entries that match the target. is_bundled_entry
skips the JSON parse when the meta never spells "bundled" and holds no
backslash (so an escaped key still takes the parse). Malformed meta that
mentions "bundled" still fails closed.

Refs #578, #580

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@mikolalysenko Mikola Lysenko (mikolalysenko) added the arch-refactor PR opened by the scheduled architecture refactor routine label Oct 7, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review October 8, 2026 11:22
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] Merged main, CI green; ready for review.


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Oct 8, 2026
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Ready for review (burn-down agent).

  • Head: fe5a42a7ae5f1642857e75d8b2fbdacdbcdbafe7
  • CI: 515/515 check runs green (success/skipped/neutral) on this head, mergeable, no conflicts.
  • Bugbot: reviewed this head (Cursor Bugbot check: success), no unresolved review threads.
  • Changelog: untouched.

Nothing specific flagged for the reviewer beyond the PR description.


Generated by Claude Code

@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Oct 8, 2026
Any commits made after this event will not be merged.
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 8, 2026
@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Oct 8, 2026
Any commits made after this event will not be merged.
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 8, 2026
@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Oct 8, 2026
Any commits made after this event will not be merged.

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

arch-refactor PR opened by the scheduled architecture refactor routine Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants