Skip to content

Compact marker interning and conjunction memoization - #2167

Draft
zaniebot wants to merge 1 commit into
zb/cache-marker-expressionsfrom
zb/compact-marker-interner
Draft

zaniebot wants to merge 1 commit into
zb/cache-marker-expressionsfrom
zb/compact-marker-interner

Conversation

@zaniebot

@zaniebot zaniebot commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

The marker interner duplicates every node and its outgoing ranges in the uniqueness map, and its conjunction cache stores both operand orders separately. Keep immutable nodes in the shared store, index their IDs with cached hashes, and normalize conjunction-cache keys. This combines the indexing, cached-hash, and commutative-cache experiments in #2072, #2074, and #2081 on the marker performance stack. Hash-table entries retain an extra hash, but growing the index no longer rehashes large nodes or stores a second copy of their ranges.

Hyperfine 2.0.0 measurements of 021c6c422 → 6ed6756fe used release builds of the complete CLI with rustc 1.99.0 (b940084d7 2026-09-28) on an AMD EPYC-Genoa Linux VM, pinned to four CPUs. Output went to /dev/null. The supplied interpreter was CPython 3.12.13.

Commands use frozen uv workspace metadata and uv export, with the workspace-metadata preview enabled for metadata commands. Synthetic frozen script locks contain one root and conditional leaves. Repeated and distinct expressions, categorical and exclusion markers, same- and reverse-order operand pairs, and export or TOML fallback variants cover fresh interning and conjunction caches. Each command starts a fresh process and rebuilds its in-memory marker caches. OS pages and interpreter-query caches are warm. Frozen commands do not resolve, download, build, or install packages.

Values are means, parent → head. Changes are (head / parent - 1) with 95% confidence intervals; negative values indicate a reduction.

Workload Wall time Change, 95% CI Peak RSS Change, 95% CI
metadata / 64 edges / short marker / shared marker 16.2 → 16.1 ms -1.07% [-3.32%, +1.21%] 25.56 → 25.54 MiB -0.07% [-0.43%, +0.26%]
metadata / 8,192 edges / version-and-machine marker / shared marker 101.1 → 100.9 ms -0.18% [-0.95%, +0.80%] 51.16 → 51.46 MiB +0.59% [+0.44%, +0.77%]
metadata / 32,768 edges / version-and-machine marker / distinct markers 782.9 → 517.2 ms -33.94% [-34.19%, -33.71%] 271.73 → 183.52 MiB -32.46% [-32.54%, -32.38%]
metadata / 512 edges / categorical values / 32 per marker / distinct markers 186.7 → 112.1 ms -39.95% [-40.27%, -39.62%] 96.12 → 58.48 MiB -39.16% [-39.26%, -39.06%]
metadata / 512 edges / version exclusions / 32 per marker / distinct markers 236.9 → 141.8 ms -40.14% [-40.44%, -39.82%] 109.53 → 66.32 MiB -39.45% [-39.54%, -39.36%]
metadata / 16,384 edges / operand pairs / same order 291.2 → 229.5 ms -21.20% [-21.68%, -20.75%] 110.04 → 85.43 MiB -22.37% [-22.67%, -22.03%]
metadata / 16,384 edges / operand pairs / reversed order 294.7 → 229.5 ms -22.14% [-22.54%, -21.74%] 110.53 → 85.48 MiB -22.66% [-22.90%, -22.42%]
export / 16,384 edges / version-and-machine marker / distinct markers 384.9 → 265.7 ms -30.95% [-31.44%, -30.46%] 149.00 → 96.79 MiB -35.04% [-35.06%, -35.02%]
metadata / 16,384 edges / version-and-machine marker / distinct markers / general TOML fallback 471.3 → 344.4 ms -26.94% [-27.36%, -26.55%] 177.32 → 126.60 MiB -28.60% [-28.75%, -28.49%]

Each workload used ten comparison blocks with alternating revision order, one warmup followed by three measured runs per revision in each block (30 measurements per revision). The pointwise 95% percentile-bootstrap intervals use 20,000 resamples of paired block means and retain all samples. They estimate within-run uncertainty, not variation across machines, independent builds, or separate benchmark campaigns.

The seven distinct-marker or operand-pair workloads reduced runtime by 21.20% to 40.14% and peak RSS by 22.37% to 39.45%. The 32,768-edge case used about 88.21 MiB less peak RSS. Both shared-marker runtime controls are inconclusive; the 8,192-edge shared-marker control increased RSS by 0.59% (about 0.30 MiB). These effects apply to the combined indexing, cached-hash, and conjunction-cache changes; they do not establish a general resolver speedup. RSS is Hyperfine's Linux wait4 peak, not an allocation count or summed simultaneous process-tree memory.

Earlier measurements

Earlier benchmark study:

Matched 021c6c422b → 6ed6756fe1 builds on an x86-64 Linux devbox changed the 78 MB MTEB frozen export from 673.7 ms to 506.8 ms: 24.8% faster (95% CI 24.0–25.3% faster). The general TOML fallback was 20.2% faster (95% CI 19.2–20.9% faster). Each workload used 21 alternating pairs, with paired-bootstrap intervals and compiler activity excluded at pair boundaries. Mean peak RSS on MTEB was 320.8 MiB → 243.3 MiB, 24.1% lower (95% CI 23.9–24.4% lower).

Ordinary 5.5 kB built-by-uv lock: 0.2% slower (inconclusive; 95% CI 1.2% slower to 0.9% faster); ordinary 165 kB scripts/benchmark lock: 3.4% faster (95% CI 2.3–4.5% faster); generated four-extra lock: 0.9% slower (inconclusive; 95% CI 2.1% slower to 0.3% faster); generated 30-extra lock: 7.6% faster (95% CI 6.7–8.6% faster); already-compact 70-extra lock: 1.2% slower (inconclusive; 95% CI 3.9% slower to 1.0% faster).

@codspeed

codspeed Bot commented Sep 30, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by ×2.2

⚡ 1 improved benchmark
✅ 173 untouched benchmarks
⏩ 16 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ WallTime create_shared[async] 843.7 ms 381.1 ms ×2.2

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing zb/compact-marker-interner (6ed6756) with zb/cache-marker-expressions (021c6c4)

Open in CodSpeed

Footnotes

  1. 16 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@zaniebot zaniebot added the build:skip-release Disable building release binaries for a pull request label Oct 7, 2026
@zaniebot
zaniebot removed this pull request from stack #2155 October 7, 2026 23:37
@zaniebot
zaniebot added this pull request to stack #2337 October 7, 2026 23:38
@zaniebot
zaniebot removed this pull request from stack #2337 October 8, 2026 00:02
@zaniebot
zaniebot added this pull request to stack #2339 October 8, 2026 00:02
@zaniebot
zaniebot removed this pull request from stack #2339 October 8, 2026 00:19
@zaniebot
zaniebot added this pull request to stack #2341 October 8, 2026 00:19
charliermarsh added a commit to astral-sh/uv that referenced this pull request Oct 18, 2026
…22676)

We store each marker node once and keep only its hash and ID in the
uniqueness index. We also normalize conjunction cache keys so `A AND B`
and `B AND A` share an entry; disjunction uses the same cache.

Compared with #22675 on an AMD EPYC devbox, full MTEB frozen export was
15.0% faster and peak RSS fell from 299 MiB to 191 MiB. Repeated
string-atom parsing was 8.8% slower, and restricting extras across 12
shared pairs was 16.3% slower.
[Measurements](https://gist.github.com/charliermarsh/a26d9abfeb794f4de0ad0f27cdfb2a66).


[CodSpeed](#22676 (comment))
also reports about 5.9% higher simulated cost for a sparse DNF case; the
cause remains unresolved.

Ports [uv-dev#2167](astral-sh#2167).

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

build:skip-release Disable building release binaries for a pull request performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant