Skip to content

perf(lexical/index)!: drop a posting list's skip table once the decoder has checked it, so that the posting cache no longer holds a table nothing reads - #1897

Merged
mosuka merged 1 commit into
mainfrom
perf/posting-skip-table
Dec 5, 2026

Conversation

@mosuka

@mosuka mosuka commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #1858

Since Issue #1854, skip_to gallops over the decoded doc ids and no longer reads a posting list's multi-level skip table, yet the decoder kept the table in every decoded list, the posting cache counted it, and segments with deletions or in the v1 format had it rebuilt. The decoder now checks the table against the doc ids as before (Issue #1224) and drops it. On the #588 Phase 0 probe (MS MARCO, the first 1,000,000 passages), the posting cache holds 4.2 to 4.3% fewer bytes for the same lists, with the same hits, scores and totals. The writer still writes the v3 table, which an older laurus checks.

DecodedPostingList::skip_levels, a public field, is removed, hence the !.

Changes

  • laurus/src/lexical/index/inverted/core/posting.rs:
  • laurus/src/lexical/index/inverted/reader.rs: InvertedIndexPostingIterator::new and SegmentReader::filter_deleted_soa no longer build a table; comments follow.
  • laurus/src/lexical/index/inverted/posting_cache.rs: estimated_bytes no longer adds the table.
  • laurus/benches/posting_skip_to_bench.rs: its list helper no longer builds a table; the bench times skip_to, which does not read it.
  • Docs, in English and Japanese:
    • concepts/indexing/lexical_indexing.md, "Multi-Level Skip Table": the decoder reads the table only to check it, then drops it, and the posting cache holds none; v1 segments are read without one.
    • concepts/search/lexical_search.md: the posting cache's decode no longer lists the skip table.

Not as planned

The plan had the decoder check only the levels' lengths and seek past the entries. The adversarial review showed two things, and with the user's approval the decoder checks every entry as before, still without keeping the table:

  • The entries also cross-check the doc ids. Some damage to the doc ids is caught only by the table. For example, two damaged deltas that cancel out keep the doc ids ascending, their count, the byte length and the last doc id, which the block-max check compares. Checking only the lengths would let such a list through until a merge verifies the .post checksum, and its term would match other documents meanwhile.
  • A seek costs reads. On inputs without mmap (LAURUS_NO_MMAP=1, a compound file's handle window), seek discards the reader's buffer at every level.

The tests changed accordingly:

  • the damaged-entry test stays "rejected";
  • the written-table test also decodes what it writes.

Tests

Test What it checks
a_decoded_list_is_estimated_without_a_skip_table (posting_cache.rs) A list of 2,000 postings with positions, written as v3 and decoded, is estimated as its doc ids, frequencies, positions, term and struct. On main the table adds to it, so it fails there.
every_written_skip_table_matches_its_doc_ids (posting.rs, changed) For every n from 0 to 4,200, the table encode_v3 writes, read from the bytes, equals the reference table, and the decoder accepts the list with the same doc ids. It used the decoded field before.
test_round_trip_v2_writes_the_skip_table (posting.rs, changed) A v2 list of 2,000 postings round-trips, and its bytes carry the table build_skip_levels builds (at least two levels).
test_v1_decodes_without_a_skip_table (posting.rs, changed) A v1 list decodes its doc ids; no table is built for it.
a_skip_level_of_the_wrong_length_is_rejected (posting.rs, new) A level whose length is not the shape's (one entry for 16 doc ids) is rejected.

The existing corruption tests (a level longer than the file, too many levels, a table on an empty list, a wrong entry, a wrong entry when the doc ids are read alone) pass unchanged.

RED. Each element was put back to a wrong form, the posting and posting-cache tests run, and the source restored and compared with cmp:

Element Failed
E1: the decoder checks only the levels' lengths the wrong entry
E2: the decoder checks nothing the wrong entry, the wrong length, too many levels, a table on an empty list, a wrong entry when the doc ids are read alone
E3: the decoder reads one entry short in each level 13 tests, the written table and the v2 round trip among them
E4: the writer writes every entry one higher 8 tests, the written table and the v2 round trip among them (every decode of a written list rejects it)

Checks

The CI's checks, run locally on Linux x86_64 (evo-x2) with stable 1.100.1 on 1b59f23d (this change rebased on 9730730e):

Check Result
cargo fmt --all -- --check OK
Workspace clippy, --all-targets --features embeddings-all -- -D warnings OK
laurus-wasm clippy for wasm32-unknown-unknown, --tests OK
scripts/check-rustdoc.py OK
scripts/check-ci-filters.py, check-job-timeouts.py and their tests OK
scripts/check-binding-snippets.py OK
laurus tests (embeddings-all,pq-fastscan) 4,257 passed, 0 failed, 28 ignored
laurus-server, laurus-mcp, laurus-cli tests (embeddings-all) 334, 53 and 89 passed, 0 failed
posting_skip_to_bench, once in test mode 14 benchmarks ran, none failed
Node.js, Ruby, PHP, Python and WASM bindings 332, 226 (runs), 231, 358 and 89 passed, 0 failed
markdownlint on the four docs 0 warnings

CI

Run 47352740901 on 1b59f23d: all 29 jobs passed, Binding Snippets included (the docs changed). The five new and changed tests passed in the Test laurus jobs on Linux x86_64, Linux aarch64 and Windows, which passed 4,262, 4,229 and 4,230 tests with none failed.

Measurements

Instructions

The #588 Phase 0 probe (not committed) builds indexes of the first 1,000,000 MS MARCO passages, one (one segment) and default (100 segments), shared by both sides as the format does not change. Hooks added to the exported trees only report the posting caches' bytes and skip-table bytes.

  • The posting cache: every query of the probe (12 queries, a top-10 search and a count each), with the cache on, then the caches' estimated bytes.
  • The decode: with the posting cache off (enable_posting_cache: false), so that every postings() decodes, reader.postings() alone for one-term queries (postings) and a top-10 search (none). Each run made 21 repetitions; the tables give medians over 6 runs per side (ABBA, 3 rounds).
  • The null pair: the same runs with two copies of main's binary, to show this host's spread.
  • The machine: CPUs 0-7 of an AMD Ryzen AI MAX+ 395 (evo-x2); load averages 4.13 to 5.00 for the change's runs, 2.69 to 2.91 for the null pair, and 3.29 to 4.58 for the runs of the largest list.
  • The results: the top-10 hits with their scores' bits (with no total and with an exact one), the exact totals and the counts were the same on both sides for the 12 queries on both indexes.

The posting cache

Index main bytes Skip-table bytes in it This change, bytes Δ
one 10,187,901 427,980 9,759,657 -4.2%
default 10,365,592 421,432 9,917,760 -4.3%

The rest of the difference is the field's own Vec header in each cached list.

The decode

Index Query Mode main (µs) This change (µs) Δ Null pair Δ
one term american (df 19475) postings 800 804 +0.5% +1.3%
one term one (df 112650) postings 5,022 5,214 +3.8% +0.3%
one term people (df 50663) postings 2,021 2,066 +2.2% +1.0%
one and one people none 14,452 14,766 +2.2% +0.6%
one or also may used none 13,292 13,551 +1.9% +0.6%
one term american (df 19475) none 842 868 +3.1% +1.2%
one term one (df 112650) none 5,144 5,286 +2.8% +0.7%
one term people (df 50663) none 2,096 2,132 +1.7% +2.1%
default term american (df 19475) postings 1,224 1,204 -1.7% -1.6%
default term one (df 112650) postings 4,646 4,814 +3.6% -1.9%
default term people (df 50663) postings 2,667 2,653 -0.5% -0.2%
default and one people none 2,770 2,766 -0.1% -0.7%
default or also may used none 2,489 2,504 +0.6% +1.3%
default term american (df 19475) none 246 236 -4.1% -6.7%
default term one (df 112650) none 884 888 +0.3% -4.2%
default term people (df 50663) none 448 448 +0.0% -7.9%

On the one index the change's runs were 0.5 to 3.8% slower; between the two copies of main's binary, the same order gave +0.3 to +2.1% there, and −7.9 to +2.1% over all the cells. The largest list (one, 112,650 postings) was 3.6 to 3.8% slower on both indexes, so its decode alone was measured again over 5 rounds of 51 repetitions (10 runs per side): +0.3% on one and +0.9% on default, with overlapping ranges, against +0.0% and +0.4% between the two copies of main's binary. The change does strictly less work there: the same reads and the same check, without keeping the table.

Not done

  • Writing no table (option 3 of the investigation), which needs a new posting format version. It is left to the next time the format changes for another reason.
  • The write-side cost of the table (its copy and build at flush and merge), which this change does not touch.

…er has checked it, so that the posting cache no longer holds a table nothing reads

Since Issue #1854, `skip_to` gallops over the decoded doc ids and no
longer reads a posting list's multi-level skip table. The decoder still
kept the table in `DecodedPostingList::skip_levels`, the posting cache
counted it, and a segment with deletions or a v1 segment had it rebuilt.

The decoder now reads the table only to check it against the doc ids, as
before (Issue #1224), and drops it. The table is no longer rebuilt after
deletion filtering, for v1 segments, or by `from_posting_list` and
`InvertedIndexPostingIterator::new`. The writer still writes the v3
table, which an older laurus checks.

BREAKING CHANGE: `DecodedPostingList::skip_levels` is removed.
@mosuka
mosuka merged commit 26d5bd6 into main Dec 5, 2026
29 checks passed
@mosuka
mosuka deleted the perf/posting-skip-table branch December 5, 2026 04:25
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.

perf(lexical/index): decide what to do with the posting skip table now that skip_to does not read it

1 participant