Repository navigation
Fix Poetry/PDM scans re-parsing the lock (#1473, #1624) - #1684
Conversation
Assisted-by: Claude Code:claude-opus-5-5
A hosted scan of a Poetry or PDM project parsed the whole lock five or six times: the lock inventory, VEX discovery before the rewrite, the PDM redirect's presence probe and the batch rewrite all parsed the same original bytes, and VEX discovery parsed the written lock again right after the rewrite had parsed that exact text. On the 400-package bench locks each parse is about a tenth of the scan. Those readers now share one read-only parse per lock text, kept in a two-slot bytes-keyed memo (the lock as read and as written). The rewrite seeds it with the parse of its own output, so reading the written lock back is free. Output is byte-identical; callgrind on the bench fixtures drops pdm/hosted from 378M to 249M instructions (-34%) and poetry/hosted from 372M to 255M (-31%). Fixes #1473, #1624 Assisted-by: Claude Code:claude-opus-5-5
The one-dep-at-a-time rewrite hands each dep's output parse straight to the next dep, which mutates it in place. Sharing that parse with the lock memo made every later step copy it first. Only the batch rewrite, whose output is read back by VEX discovery, shares it now. Assisted-by: Claude Code:claude-opus-5-5
The one-dep-at-a-time rewrite parsed each intermediate lock through the shared memo, which pushed out the original and written locks that VEX discovery reads back, and then copied every parse because the memo held it too. Those texts are parsed privately again; the Poetry stale-install check reads the shared parse instead of its own. Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 562f0ab. Configure here.
|
Ready for review (burn-down agent).
Slack announcement not sent: this run had no Slack send tool. Generated by Claude Code |
|
Labeled Ready for review (burn-down agent).
Generated by Claude Code |
Final review briefWhat it does. Hosted Poetry/PDM scans used to parse the same lock 5–6 times (lock inventory, VEX discovery before and after the rewrite, the PDM probe, Risk: low–medium. It's a perf-only refactor on a shared parse path. A cache hit needs an exact byte match on the key, so a stale slot can only cost a parse, not give a wrong answer. Under Look here
Verified
Changes I made: none. Open questions: none blocking. The retention and multi-lock trade-offs are listed in the description; a miss costs exactly what Auto-merge is armed, so approving sends this straight to the merge queue. Generated by Claude Code |
LLM Description written by Claude Code:claude-opus-5-5
Fixes #1473
Fixes #1624
Summary
Hosted Poetry and PDM scans now parse each lock text once instead of five or six times. Output is byte-identical. On the bench fixtures (400 packages, 12 patched), callgrind shows:
main(aa69125)pdm/hostedpoetry/hostedBefore this PR,
toml_edit::Document::parsewas 43–45% of all instructions in both scenarios. After it, the parse share is 22–27%.Root cause (shared by both issues)
The Poetry and PDM hosted paths parse the same lock from several readers that knew nothing of each other. Callgrind callers of
Document::parseonmain:inventory_{poetry,pdm}_lock)hosted::engine::rewrite)lock_contains, viaLockParse)lock_fragments::rewrite_batch: the originallock_fragments::rewrite_batch: the renderingrecorded_discovery)Only two distinct texts exist: the lock as read, and as rewritten.
rewrite_batchalready parsed the rewritten text (to pair fragments) before VEX parsed it again.Fix
utils::lock_fragments::parse_lockis a read-onlyDocument<String>parse behind a two-slot, bytes-keyedParseMemo. It uses the same byte-equality contract as the vendor memos: a stale slot only ever costs a parse.extract_poetry/extract_pdm,LockParse::parsed(the PDM presence probe),rewrite_batch's original, and the Poetry stale-install check all read through it.rewrite_batchseeds the memo with the parse of its own output, so the post-write VEX read is free.LockParse::take) copies a shared parse when one exists. Otherwise it parses privately: its intermediate texts are never read again and must not evict the two that are.toml_or_diag's diagnostic formatting is factored intotoml_result_or_diag, so the shared parse produces the samelockfile_unparseabletext.cfg(test)the memo is thread-local, soPARSEScounts stay exact across parallel tests.No wrapper (
npm/,pypi/,gem/) changes: this is core-internal.Tests (red → green)
vex::discover::pypi_locks::tests::poetry_scan_parses_each_lock_text_once(Poetry 1.2.2 / 1.8.5 / 2.1.4)vex::discover::pypi_locks::tests::pdm_scan_parses_each_lock_text_once(PDM 2.11.2 / 2.17.3 / 2.29.2)Each test runs the hosted sequence: inventory, then VEX, then batch rewrite, then VEX on the written lock. It asserts the refs found and the rewritten text, and the
PARSEScount. To get the red run, the memo was bypassed (memo.invalidate()before everyparse_lock):left: 5, right: 2for both. The existingmany_patches_render_the_lock_oncetests (one render, two parses for Poetry) still pass.Commands run locally:
cargo fmt --all -- --check✅cargo clippy --workspace --all-features -- -D warnings✅cargo test --workspace --all-features --no-fail-fast: 7,522 CLI and 6,681 core tests pass. 10 fail, and all 10 are environmental in this sandbox (root user, no egress):chmod 0o555write-failure tests. The 4 in core fail identically on unmodifiedmain.e2e_bun_lockb::binary_shared_bundled_record_hosted_pin_is_managedneedspatches-api.socket.dev.e2e_vex_build -- poetry:: --ignoredwith Poetry 2.4.3 ✅ (4/4)e2e_vex_build -- pdm:: --ignoredwith PDM 2.29.2 ✅ (2/2)in_process_redirect_poetry,in_process_redirect_pdm,hosted_superseding_pypi,e2e_pypi✅--jsonoutput and every written project file (sha256) are identical./code-review highfindings not fixedThe review found no correctness bugs. Fixed: step-path memo pollution and copies (562f0ab), the Poetry stale-install check's own parse, and an overclaiming doc comment. Not fixed:
poetry.lockfiles, or with bothpoetry.lockandpdm.lock, can evict the root lock's slots. A miss costs exactly whatmainpays today.ParseMemo's API. Keying ondoc.raw()is a possible follow-up for every memo.Follow-ups (not in this PR)
What remains in
rewrite_batchis per-dep linear scans:pdm_lock_fragments_inis called 24× (6% Ir) andplan_pdm_rewrite12× (3%), each walking every[[package]]. Indexing packages by canonical name once per batch would remove most of that.https://claude.ai/code/session_01M3qyYKFZLy31MhprAsdm24
Note
Medium Risk
Touches shared parsing for lock inventory, VEX discovery, and redirect rewrites; behavior should be equivalent but incorrect memo invalidation could theoretically serve stale parses (mitigated by byte-equality keys and bounded retention).
Overview
Hosted Poetry and PDM scans were parsing the same
poetry.lock/pdm.lockbytes repeatedly (inventory, VEX discovery, redirect probes, batch rewrite). This PR routes those read-only parses throughparse_lock, a two-slot byte-keyedParseMemoinlock_fragments, so each distinct lock text is parsed at most once per run (original + rewritten after batch rewrite seeds the memo viashare_lock).LockParseandrewrite_batchuse sharedArcdocuments; mutable rewrite paths still clone when needed. Lock inventory, VEXextract_poetry/extract_pdm, and Poetry’s stale-installpre_1_4_writerprobe go through the same entry point; VEX addstoml_result_or_diagso shared-parse failures keep the same diagnostics. Tests assert the hosted scan does two whole-lock parses per text (fixes #1473 / #1624); output stays byte-identical.Reviewed by Cursor Bugbot for commit 562f0ab. Configure here.
Generated by Claude Code