Skip to content

Layout 16: builds end at four segments, streaming merges; an x86-64-v4 build behind a loader - #107

Merged
bweis merged 1 commit into
mainfrom
pr/perf-integrate16
Oct 16, 2026
Merged

bweis merged 1 commit into
mainfrom
pr/perf-integrate16

Conversation

@bweis

@bweis bweis commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Layout 16, from tinshape/perf-integrate16 (f282037). Indexes built at layout 15 need a REINDEX.

Builds end at four segments; merges stream (page layout 16).

  • An index build ends with initial_segment_count segments of about equal size: 4 by default, as TIN's default build gives. Each is at most 16 GiB; a small index gets fewer, so that each holds at least 1 GiB.
  • initial_segment_count is now honored as an index option. An unset target_segment_count follows it, as TIN's does.
  • Every merge streams its inputs one range at a time and spills what it builds to temporary files. Its memory is a few bytes per document rather than the bytes of its segments.
  • Segment and pending runs record their length in 64 bits on the meta page; a page table's length comes from its run. The pending-free list holds 40 runs (was 48).
  • Maintenance merges (inserts', VACUUM's, the workers') take at most max_merged_segment_size (2000 MB unset, as TIN's) and leave a build's larger segments alone. VACUUM reads a segment's documents without reading the segment.
  • tnsmerge (bench) merges dumped segments offline; tnsreplay prints a census.

x86-64 loader.

  • x86-64 Linux packages ship two builds, the baseline and one for x86-64-v4. A small loader installed as stannum.so picks the v4 build on CPUs with all of x86-64-v4 (and an OS that saves the AVX-512 registers), and the baseline elsewhere.
  • script/install-release builds and installs all three files. STANNUM_LOADER_LEVEL forces a build; SHOW stannum.cpu_level reports the running one. aarch64 is unchanged.
  • The x86-64 benchmark image builds the loader by default, so a campaign measures what ships; --target-cpu x86-64 builds the baseline alone.
  • Two image fixes: the summary grep no longer fails under the amd64 base's pipefail, and script/rustc-cpu-level is copied into the image, which every v4/loader image build needed.

Term lookups by an eight-byte key.

  • The term map's block index is searched by each sampled block's first eight bytes, held in a dense array. Before, nearly every step missed the cache in a memcmp.
  • 1.1–2.7% more queries per cycle in every style on Sapphire Rapids (paired hyperthreads).

Group frontiers bounded without branches.

  • A frontier's first pairs are decoded, then bounded, with no branch on how many it holds or on each varint's length.
  • score disjunctions +2.1% per core cycle, full_score disjunctions +0.9%.

Tooling: a paired-core (hyperthread) A/B gate (devbox-htpair-ab.sh, htpair_gate.py, htpair_summary.py), devbox-seg4-ab.sh, devbox-loader.sh, and tnsreplay pinning.

PGO retrained on layout 16: aarch64 (7ad38b4), x86_64 and the new x86_64-v4 profile (f282037). Each answered 3762 + 3762 queries with 0 differences.

Answers. Scores are bit-identical over the 150M trace (1228 / 1253 / 1252 equal, 0 different; --full byte-identical in all 3 styles), on aarch64 and on x86. Ranked oracle 3762/3762. Conformance against TIN 1.0.3 and 1.0.4 is unchanged, 0 FAIL.

150M database: built in 159.7 min (layout 15: 166.5, on a loaded Mac), 4 segments (layout 15: 13), index 36.41 GB (+0.36%). The segments aren't balanced yet (7.1 / 15.5 / 7.0 / 6.7 GB): the 15.5 GB one comes from a tier merge during the build. This is a follow-up.

x86 replay, Sapphire Rapids (m7i.4xlarge), paired-core gate, 3 rotated rounds, each layout on its own dump, answers the same every round. Queries per core cycle:

i16 vs i15 v4 build vs baseline
conj +10.2% −0.4%
phrase +14.2% +0.1%
disj +4.5% +0.2%
full conj +7.3% +3.0%
full phrase +12.7% +2.9%
full disj +2.5% +5.4%
geomean +8.5% +1.8%

Instructions per query fell 2.9–12.8%.

Local M4 campaign (new layout-16 database, run with the CI runners idle). QPS score / full_score, change against layout 15 (d07348e):

QPS change
conj 1364 / 852 +8.9% / +3.1%
disj 336 / 131 −0.9% / −3.5%
phrase 997 / 676 +4.1% / +1.5%
mixed 624 / 284 −0.5% / −3.7%

full_score disjunctions and mixed are 3.5–3.7% slower locally, although the x86 replay shows full disj +2.5%. This will be checked on i7i before acting on it.

Verified locally: script/test-all full green (pgrx 227 passed), clippy pg17/pg18 and fmt clean, x86 tests under Rosetta (scalar and AVX2), PGO 40/40 on aarch64. The strict loader image with both x86 profiles has not been built on a box yet.

@bweis
bweis merged commit ca9c945 into main Oct 16, 2026
12 checks passed
@bweis
bweis deleted the pr/perf-integrate16 branch October 16, 2026 21:58
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