8000 perf: unstable sorts for unique query metadata (#795) by adityamukho · Pull Request #799 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

perf: unstable sorts for unique query metadata (#795) - #799

Merged
adityamukho merged 1 commit into
v3from
perf/795-unique-sorts
Oct 30, 2026
Merged

adityamukho merged 1 commit into
v3from
perf/795-unique-sorts

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Part of #795 (follow-up to the #772 audit, #798).

Change

sort → sort_unstable at the three sites the audit found:

  • prepared.rs::collect_slot_names — names drained from a HashSet: unique.
  • plan.rs::Builder::union — a branch's own variables from by_var keys: unique.
  • plan.rs::Builder::sub — imports (name, slot) sorted by slot.

Import-slot invariant. Every Slots::by_var insertion in plan.rs (7 sites) uses a slot fresh from Slots::add, so distinct names never share a slot. Equal keys therefore mean the same variable named twice ((not-join [?x ?x] …)), whose entries are identical: tie order cannot change the plan or results. Comment added at the sort. Optimizer cost/selectivity sorts and legacy replay sorts are untouched.

Tests

New repeated_join_variable_matches_single (engine/tests.rs): repeated join variables in not-join and or-join answer exactly as the same clause naming each once, under the chosen, hashed and correlated body forms. Full cargo test passes; MSRV 1.89 check --all-targets passes; clippy findings identical to base.

Measurements (v3 8c6c4a1ac, rustc 1.99.1, release)

bytes base string sorts import sort all three
native CLI 1,263,592 1,263,240 (−352) 1,262,936 (−656) 1,262,584 (−1,008)
WASI 879,785 878,753 (−1,032) 879,065 (−720) 878,033 (−1,752)
browser --lib 1,525,738 1,524,823 (−915) 1,524,767 (−971) 1,523,852 (−1,886)

Savings are additive here. Prepare + plan + execute micro-benchmark (3 slots, or-join, not-join; ad-hoc or + not-join query), base and candidate on separate sockets, swapped over 4 rounds: prepared 77,352 → 77,467 ns (+0.15%), ad-hoc 73,950 → 73,550 ns (−0.5%), i.e. within noise.

No public API, format, size cap or coverage floor change. CHANGELOG, TEST_COVERAGE and CLAUDE.md test counts updated; no docs-site change (no syntax or architecture change).

🤖 Generated with Claude Code

https://claude.ai/code/session_01H2a7Qo5yfvBEjzSuUoB2n9

Prepared slot names and an `or`'s branch variables come from a set or a
map's keys, so they are unique. Every variable in the planner's slot map
has its own slot, so a subplan's imports tie only when a join variable
is named twice, and those entries are identical. Sorting all three with
`sort_unstable` keeps order and plans unchanged and drops the stable
sort's merge code.

Release sizes on v3 (rustc 1.99.1): native CLI 1,263,592 -> 1,262,584
(-1,008), WASI 879,785 -> 878,033 (-1,752), browser lib 1,525,738 ->
1,523,852 (-1,886). Prepare/plan micro-benchmark unchanged within noise.

Adds a test that a repeated join variable in `not-join`/`or-join`
answers as the same clause naming it once, under every body form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H2a7Qo5yfvBEjzSuUoB2n9
@codecov
codecov Bot commented Oct 30, 2026
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@adityamukho
adityamukho merged commit 2ff9105 into v3 Oct 30, 2026
19 checks passed
@adityamukho
adityamukho deleted the perf/795-unique-sorts branch October 30, 2026 06:03
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.

1 participant

0