Skip to content

Sub-range codes for full_score conjunctions; the densest run of groups walks first (page layout 18) - #109

Merged
bweis merged 1 commit into
mainfrom
pr/perf-integrate18
Oct 18, 2026
Merged

bweis merged 1 commit into
mainfrom
pr/perf-integrate18

Conversation

@bweis

@bweis bweis commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

From tinshape/perf-integrate18 (824bb83). Page layout 18: indexes of an earlier layout must be rebuilt (REINDEX). Layout 18 is layout 16 plus sub-range codes; 17 was never shipped.

Sub-range codes for dense terms (loop/subrange).

  • A grouped record of a dense term (one in at least a tenth of its segment's documents) holds one byte per 64-slot word of each grid, per pair of its group frontier. That byte is R10's rounded-length code: the least rounded length of the word's postings at that pair's buckets.
  • A full_score conjunction's group with at least 32 candidates bounds each candidate word by its scoring terms' codes, summed in the scorer's order. It clears the words the bar cuts before reading their buckets. Other walks read no code.
  • verify_segment checks every grid posting against its code.
  • Index +1.64% at 150M rows (37.01 vs 36.41 GB).
  • On x86 (loop/subrange's paired gate): full conj +12.6%, full phrase +10.7%, their tail-25 forms −25.8% / −19.4% cycles. Other styles unchanged.

The densest run of groups walks first (loop/shortfirst, with loop/thetaseed and loop/tail25's tooling).

  • On a segment of at least 1,024 groups, the walk first takes the run of 40% of the groups (whole 64-group runs) holding the most documents per group, provided it holds at least 1.2× the segment's documents per group. Then it takes the rest.
  • Short documents score highest, so the bar forms where the winners are. The other groups then walk under a near-final bar.
  • A disjunction walking groups in ranges now seeks each term to the next range, instead of stepping through the groups between ranges (0a2b35e).
  • Exact by construction: rows keep the exhaustive (score, tid) order whatever order candidates arrive in.
  • On x86 (loop/shortfirst's gate): +5.60% paired over the six styles, every style at least +3.6%.
  • Rechecked on the new layout (M4 instructions, --short-first 0 vs 400): −3.1% over all forms, every style lower, tails −5 to −9%.

Dropped by the server pair (on trial).

  • Length codes in the TF tail (loop/lencode 744b9be, combined with subrange into one layout 18 in 804a92b). Measured as i18 vs i18 without them, each on its own 150M database: +1.48% throughput. Rounds were +1.57 / +1.25 / +1.62. Every style was positive, the worst being full conj +0.86; the target score disj was +1.51 and full disj +2.67. L2 misses fell 4–19%, for +3.06% index size. That is below the keep bar (+1.5% geomean, or +2% on the target), so it was reverted in e170cdd.
  • Kept-page cap for wide disjunctions (8b19ee7): −0.17%. Score disj was −1.19%, with L2 misses up 6.5%, and full disj 0.00%. Reverted in 9a22530.

Tooling.

  • tnsreplay: --mmap, per-query pinq counts and ins/cyc columns, --plan STYLE:MODE:@FILE, --order matches|density, --short-first, --lead, --heap-perm, --prepass, --seed-rank, --rows-at, --group-stats, and a sub-range census.
  • htpair_gate.py --tail-gate; the fixed tail-25 sets in benchmarks/aws/tail/; tnssubsize.
  • dump-segments.py reads layout 18 (it was pinned at 16).
  • devbox.sh --disk goes up to 400 GiB.

PGO, retrained on this tree: x86_64 and x86_64-v4 (4c745a5, trained over the layout-18 database), and aarch64 (824bb83). Score answers differ from pg-ranked in 0 cases, and full_score answers match i17's trainings at both levels. PGO coverage is 40 of 40 for x86-64 and for x86-64-v4 in the strict default (loader) image, and 40 of 40 on aarch64.

Answers.

  • The ranked oracle matched on 3762/3762 queries, on the new database (plain image and strict PGO image) and also on the length-code database.
  • M4 tnsreplay --mmap on a fresh dump of the shipped layout: 1228 / 1253 / 1252 equal, 0 different. --full is byte-identical to f0962a8 in all 3 styles. The combined layout with length codes gave the same.
  • x86 --expect (v4 + replay PGO, with length codes) gave 0 different.
  • In the server pair, i18's answers matched i17's on all 4642 list queries (ids and scores). The arm without length codes matched on the 3480 it answered before a timeout.
  • Conformance against TIN 1.0.3 and 1.0.4 is unchanged, 0 FAIL.

x86 replay, Sapphire Rapids (m7i.4xlarge), paired-core gate, 3 rounds, each arm built with its own replay PGO profile (x86-64-v4). i18 includes length codes and the cap, each arm runs on its own dump, and tail-25 is included. Queries per core cycle, i18 vs i17:

paired tail-25 cycles
conj +3.66% −6.0%
phrase +4.36% −6.9%
disj +8.78% −8.4%
full conj +12.36% −22.7%
full phrase +11.81% −18.7%
full disj +9.65% −9.4%
geomean +8.39% (rounds +8.4/+8.8/+7.3), KEEP, TAIL-KEEP

Server pair, Sapphire Rapids (PG 18.6 PGDG on two hyperthreads of one core, 2 clients, fixed seeded passes, 3 rotated rounds). Loader builds without PGO on every arm; the v4 build was picked each time. Each arm used its own 150M database. Throughput vs i17:

i18 i18 without length codes i18 without the cap
conj +4.47% +2.76% +3.54%
phrase +6.59% +5.36% +7.30%
disj +8.15% +6.54% +9.45%
full conj +9.67% +8.73% +9.33%
full phrase +10.52% +9.44% +10.90%
full disj +9.25% +6.41% +9.26%
geomean +8.09% +6.52% +8.27%

The shipped tree is the middle column minus the cap; the cap measured at −0.17%. EXPLAIN MiB/query vs i17: score −1.2 / −2.2 / −2.6% and full −1.3 / −5.8 / −2.5% (conj / disj / phrase).

Local M4 campaign (new layout-18 database, strict aarch64 PGO image, runner CPU 0% in every run). QPS score / full_score, change against i17 (887c5e8, layout-16 database):

QPS change p99 ms (vs i17)
conj 1422 / 946 +1.0% / +6.7% 26.9 / 58.7 (27.6 / 71.1)
disj 350 / 141 +2.2% / +5.7% 103.9 / 247.3 (107.4 / 264.0)
phrase 1071 / 737 +1.5% / +3.0% 49.6 / 95.0 (53.5 / 118.6)
mixed 658 / 315 +1.3% / +5.3% 89.0 / 196.1 (90.0 / 206.1)

150M databases (local, mock-build v2):

  • Shipped layout: import 13.4 min, index build 162.4 min, 4 segments (16.8M / 100.7M / 18.9M / 13.7M documents), index 37.01 GB.
  • With length codes: index build 160.8 min, 38.14 GB.

Open items

  • Length codes missed the bar by 0.02 pt. Every server cell was positive, and the gain is in pages and L2 misses. A cheaper placement might clear it: codes only on records of at most 3% of the documents were +2.2% size in the census, keeping most of the page savings.
  • The PGO server pair (final vs i17, both with PGO) was not run within budget. The no-PGO pair above is the measured server number.

Verified locally: script/test-all full green (pgrx 228 passed), clippy pg17/pg18 and fmt clean, x86 tests under Rosetta (no AVX, AVX scalar, AVX2).

@bweis
bweis merged commit 3f1ada9 into main Oct 18, 2026
13 checks passed
@bweis
bweis deleted the pr/perf-integrate18 branch October 18, 2026 04:37
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