Skip to content

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

Done

Description

@mosuka

Background

Since #1854, InvertedIndexPostingIterator::skip_to gallops over a posting list's decoded doc ids and no longer reads the multi-level skip table (DecodedPostingList::skip_levels, #503). The table is still part of the v2/v3 posting format, and at query time it now only costs:

  • Memory. Every decoded posting list keeps it: about one u32 per 7 postings (n/8 + n/64 + …), some 14% of the doc-id array. The posting cache counts it (laurus/src/lexical/index/inverted/posting_cache.rs:43).
  • Load time.

Goal

Decide, with measurements, what to do with the table now that no reader uses it:

  1. keep it in memory as today;
  2. skip its bytes on decode and keep no copy, still checking its shape, or the whole of it;
  3. stop writing it in a new format version.

Acceptance criteria

  • The memory and the decode time the table costs are measured on the perf(lexical/search): no BulkScorer interface for dense AND/OR fast path #588 Phase 0 probe (MS MARCO 1,000,000 passages): the posting cache's size, and a search after the cache is cleared.
  • The chosen option is implemented, or this Issue is closed with the measurements if the cost is not worth a change.
  • Segments of every existing format version stay readable, with the decoder's corruption checks no weaker than the measurements justify.

References

Tasks

Activity

  1. added
    enhancement
    on Dec 2, 2026
  2. mosuka commented on Dec 4, 2026

    @mosuka
    OwnerAuthor

    Investigation

    Read on main at 73768e6e, and measured on the #588 Phase 0 probe (MS MARCO, the first 1,000,000 passages) with a prototype of option 2. Nothing reads the skip table at query time. It holds about 4% of the posting cache's bytes and 9.3% of the .post file. Skipping it on decode freed that 4% and left the decode time within the noise (−3.3% to +0.6% for postings() alone), with the same hits, scores and totals.

    What the table still costs

    • Written for every posting list in the v2 and v3 formats (production always writes v3). The encoder copies the doc ids into a u32 array and builds the table from it (laurus/src/lexical/index/inverted/core/posting.rs:864-892). Its size is about n/7 u32s, about 14% of the doc-id array.

    • Read on every decode, which is every posting-cache miss (posting.rs:1262-1284):

    • Rebuilt from the doc ids:

      • on a cache miss in a segment with deletions (SegmentReader::filter_deleted_soa, laurus/src/lexical/index/inverted/reader.rs:1379-1380);
      • for a v1 segment (posting.rs:1485-1489);
      • by InvertedIndexPostingIterator::new (reader.rs:177-178) and DecodedPostingList::from_posting_list (posting.rs:442), which build lists from postings in memory.
    • Not read anywhere else:

      What skip_to relies on is that the doc ids strictly ascend, which check_ascending_doc_ids checks (Issue fix(lexical): reject inconsistent on-disk data that the dictionary and posting decoders silently accept #1235) apart from the table.

    What it costs on MS MARCO

    The probe built the one (1 segment) and default (100 segments) indexes in 52 s and 42 s, on CPUs 0-7 of an AMD Ryzen AI MAX+ 395 (evo-x2). Measuring hooks were added to the exported trees only (not committed): the bytes the encoder wrote for skip tables, and the posting caches' bytes and skip-table bytes.

    On disk (the one index, rebuilt with LAURUS_NO_COMPOUND=1 to see the .post file):

    What Bytes Share
    Skip tables written 15,204,549 —
    .post 162,736,978 9.3% of it
    The whole index 750,275,926 2.0% of it

    In the posting cache, after every query of the probe (12 queries, a top-10 search and a count each), with the cache on:

    Index Cache bytes Skip-table bytes Share
    one 10,187,901 427,980 4.2%
    default 10,365,592 421,432 4.1%

    The cache's estimate counts the lists' positions too, which this index stores, so the share of a list without positions is larger.

    The decode time. These runs had the posting cache off (enable_posting_cache: false), so every postings() decodes:

    • The prototype (option 2) reads only each level's length, seeks past its entries, checks the lengths against the shape built from the doc ids, and keeps no table. It also does not rebuild the table on deletions or for v1.
    • What was timed: reader.postings() alone for one-term queries (postings), and a top-10 search (none). Each probe run made 21 repetitions; the table gives medians over 6 runs per side (ABBA, 3 rounds), at a load average of 3.10 to 3.65.
    Index Query Mode main (µs) Prototype (µs) Δ
    one term one (df 112,650) postings 5,270 5,096 −3.3%
    one term people (df 50,663) postings 2,016 2,024 +0.4%
    one term american (df 19,475) postings 780 784 +0.6%
    one term one none 5,312 5,220 −1.7%
    one AND one people none 14,732 14,550 −1.2%
    one OR also may used none 13,564 13,407 −1.2%
    default term one postings 4,765 4,784 +0.4%
    default term people postings 2,724 2,690 −1.2%
    default term american postings 1,245 1,208 −3.0%
    default term american none 246 234 −4.9%
    default AND one people none 2,798 2,731 −2.4%

    Every difference is within this host's noise floor (±3 to 9%), so the table's reading and checking do not show against the rest of the decode.

    The results. For the 12 queries on both indexes, 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.

    Not measured: the write-side cost (the copy and the build per posting list at flush and merge time). Option 3 is the only one that removes it.

    The options

    1. Keep 2. Skip on decode, keep no copy 3. Stop writing (a new format version)
    Posting cache +4% freed freed
    .post on disk +9.3% +9.3% freed for new segments
    Decode time — within the noise within the noise
    Write time — — the copy and build removed (not measured)
    Corruption check every entry the lengths only, or every entry read into a scratch buffer and dropped none for new segments; old ones as option 2
    Format — unchanged a v4 posting format: older laurus cannot read new segments; v2 and v3 stay readable

    Open points for the plan

    • Which option.
      • Option 2 is local to the decoder and the cache, and keeps the format.
      • Option 3 also saves 9.3% of .post and the write-side work, but it is a format change: an older laurus could not read the segments it writes.
    • Under option 2, how much to check. The lengths alone keep the decoder's bounds. Every entry, read into a scratch buffer, keeps Issue fix(lexical): return corruption errors instead of panicking in the posting and dictionary decoders #1224's corruption check as it is, at a cost the probe did not see. A wrong entry cannot mislead skip_to, which does not read it.
    • The public field. DecodedPostingList::skip_levels is a public field of a public type. Removing it is a breaking change; leaving it always empty is not, but keeps a field that means nothing.
  3. mosuka commented on Dec 4, 2026

    @mosuka
    OwnerAuthor

    Plan

    Per the investigation, option 2: the decoder skips the skip table and keeps no copy of it, and the writer keeps writing it. The posting cache frees about 4% of its bytes (MS MARCO); the decode time did not change measurably in the prototype.

    Scale L, on evo-x2 (Linux). Windows and aarch64 Linux are left to the CI's Test laurus jobs.

    Decisions

    1. Option 2. The format stays v3. The decoder skips the table and keeps no copy; the writer does not change. Option 3 (stop writing the table in a new format version) is left to the next time the posting format changes for another reason.
    2. What the decoder checks: the shape only. The number of levels and each level's length are checked against the shape built from the number of doc ids. The entries are skipped with seek, not compared.
    3. DecodedPostingList::skip_levels is removed, a breaking change to a public type, so the title carries a !.

    The shape

    • Nothing reads it, so nothing keeps it. No search reads the table, so the decoder does not build it in memory, and the posting cache holds more lists in the same budget.
    • The format does not change. The writer still writes the v3 table, whose entries an older laurus still checks when it reads new segments. A test keeps checking that the written table matches the doc ids.
    • Skipping safely. The levels' count and lengths, checked against skip_level_shape(n), bound what is skipped. The entries are not used, so they are not checked: a damaged entry cannot change a result. What skip_to relies on, strictly ascending doc ids, stays checked (Issue fix(lexical): reject inconsistent on-disk data that the dictionary and posting decoders silently accept #1235).
    • Checksums. StructReader::seek ends the reader's running checksum, but a segment's checksums are verified per file, through a separate read (verify_file_checksum), so a seek inside a decode does not weaken them.

    Changes

    • laurus/src/lexical/index/inverted/core/posting.rs:
      • decode_doc_ids reads the level count and each level's length, bounded by the bytes left with checked_capacity_u64 as now, and seeks past the entries. Once the doc ids are decoded, a sequence of lengths other than skip_level_shape(n) is the same "segment is corrupted" error as now.
      • Removed: DecodedPostingList::skip_levels, DecodedDocIds::skip_levels, skip_levels_match, check_skip_levels, the v1 rebuild in decode_soa_inner, and the build in DecodedPostingList::from_posting_list.
      • Kept: build_skip_levels and skip_level_shape, which the writer and the shape check use.
      • Doc comments describe the format's levels and that the decoder skips them (Issue perf(lexical/index): decide what to do with the posting skip table now that skip_to does not read it #1858).
    • laurus/src/lexical/index/inverted/reader.rs: InvertedIndexPostingIterator::new and SegmentReader::filter_deleted_soa no longer build a table; the test helper drops the field.
    • laurus/src/lexical/index/inverted/posting_cache.rs: estimated_bytes no longer adds the table; its doc and test follow.
    • laurus/benches/posting_skip_to_bench.rs: its list helper drops the table. The bench times skip_to, which does not read it.
    • Docs, in English and Japanese:

    Tests, written first

    • The cache's estimate (posting_cache.rs): for a list written as v3 and decoded, estimated_bytes is the sum of the doc ids, frequencies, positions, term and struct, with no table. On main the table adds to it, so it fails.
    • A damaged entry is skipped (posting.rs): a v3 list with one table entry changed decodes to the same doc ids, frequencies and positions as before. On main it is rejected ("does not match").
    • The shape is still rejected (posting.rs; the existing tests stay):
      • a level longer than the file;
      • too many levels;
      • a table on an empty list;
      • a level whose length differs from the shape (new).
    • The writer does not change (posting.rs): every_written_skip_table_matches_its_doc_ids reads the written table from the encoded bytes through a test helper instead of the decoded field. For every n from 0 to 4,200, it still equals build_skip_levels.
    • The same results: the existing posting, reader and search tests (v1, v2 and v3 lists, segments with deletions) pass as they are.
    • RED. Each part is put back, the tests run, and the source restored and compared with cmp. cargo is stopped with its whole process group on a time limit.
      • E1: the decoder compares the entries too. The damaged-entry test fails.
      • E2: the decoder does not check the shape. The shape tests fail.
      • E3: the decoder seeks one level short. The shape tests or the doc-id decode fail.
      • E4: the writer writes a wrong table. The written-table test fails.
      • E5: estimated_bytes counts the level lengths; the exact form is fixed with the test.

    Verification

    • RED and GREEN.
    • The CI's checks:
      • fmt;
      • the workspace's clippy with --all-targets --features embeddings-all, and the wasm clippy;
      • the tests of laurus (embeddings-all,pq-fastscan), the server, MCP and the CLI;
      • check-rustdoc.py;
      • check-ci-filters.py, check-job-timeouts.py and their tests;
      • check-binding-snippets.py;
      • the five bindings;
      • markdownlint on the docs.
    • The bench posting_skip_to_bench builds and runs (cargo bench --no-run, and one short run).
    • The cost, main against the change, as ABBA over 3 rounds on CPUs 0-7, with the load average recorded, on the investigation's probe and indexes (the format is the same on both sides):
      • The posting cache's size after every query. Expected: −4%.
      • The decode alone (postings(), cache off) and a top-10 search, on the one and default indexes. Expected: no difference.
      • The results: the same top-10 hits with their scores' bits, exact totals and counts.
    • An adversarial review.

    Out of scope

    • Option 3, writing no table in a new format version.
    • The write-side cost (the table's copy and build), which option 2 does not change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions