Skip to content

perf: galloping search in sealed LID iterators' NextGeq - #490

Open
radmirnovii wants to merge 1 commit into
ozontech:mainfrom
radmirnovii:perf/lids-gallop-nextgeq
Open

perf: galloping search in sealed LID iterators' NextGeq#490
radmirnovii wants to merge 1 commit into
ozontech:mainfrom
radmirnovii:perf/lids-gallop-nextgeq

Conversation

@radmirnovii

Copy link
Copy Markdown

Description

NextGeq in the sealed LID iterators runs a binary search over the remaining
chunk slice on every call. The AND/OR zigzag sends monotonically increasing
targets while the slice narrows from the consumption edge, so the answer is
almost always near the edge — instrumented on a 2M-doc fraction: ~50% of calls
land at distance 0 and 99.9% within 16, while binary search pays
log2(remainder) ≈ 14 probes regardless. This PR replaces it with an
exponential (galloping) search from the edge, ~2·log2(d) probes — the same
uncapped scheme as Lucene's
IntArrayDocIdSet.advance
and RoaringBitmap's
advanceUntil,
which seq-db already depends on for skip masks.

The worst case is bounded at ~2× binary (2·log2(d) ≤ 2·log2(n)) and far jumps
are self-limiting (jumps over one chunk sum to at most its length): an AND
built deliberately from a skewed pair (freq ratio ≈1450, 71% of calls in the
far zone) measures at parity. A capped variant was measured and rejected — it
hurts the common zone and rescues regimes that did not occur across ~6M
instrumented calls (max distance < 128).

Benchstat, n=10, in-process Sealed.Search, 2M-doc fraction, vs main:

scenario diff
3-token AND −21.8%
(a OR b) AND c −10.8%
2-token AND −4.5%
skewed ANDs (ratio ≈285 / ≈1450) ~
13 other scenarios (needle hit/miss, aggregations, histogram, wildcard/contains, fetch, active fraction, pure OR, AND NOT) ~

Search results are byte-identical to main on a 57-query corpus (IDs and
order in both sort directions, aggregation bins, fetched docs).

Note: fracmanager/TestCapacityExceeded is red on current main (a73114c)
independently of this change.


  • I have read and followed all requirements in CONTRIBUTING.md;
  • I used LLM/AI assistance to make this pull request;
Model: Claude Fable 5 (claude-fable-5), via Claude Code
Prompt: interactive session, no single prompt. Task: performance research of
seq-db search internals (profiling, microbenchmarks, adopt/reject verdicts
backed by numbers). Directives shaping this PR: deep-dive galloping; prove
edge-locality with in-engine instrumentation rather than synthetic tests;
write a standalone PR with edge-case/regression justification and prior-art links
Extent: code (gallop.go, test, call sites), benchmarks, and this PR text
were AI-generated under the author's direction and review.

@eguguchkin

Copy link
Copy Markdown
Collaborator

@seqbenchbot up main

@seqbenchbot

seqbenchbot commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Oh-oh, @eguguchkin ('>o.o)'>!

Something went wrong and I couldn't process your request.
Please take a closer look at error message:

unexpected argument up

@eguguchkin

Copy link
Copy Markdown
Collaborator

@seqbenchbot --help

@seqbenchbot

seqbenchbot commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Hey, @eguguchkin *\ (^_^)}!

Below is the help message you've requested.
Please notice that I support shell-like interface for interaction!

Usage: @seqbenchbot <command>

Flags:
  -h, --help    Show context-sensitive help.

Commands:
  start bulk <reference> [flags]
    Bulk write scenario

  start mixed <reference> [flags]
    Mixed scenario

  start search-logbench <reference> [flags]
    A collection of different queries, each cold and hot

  start search-regular <reference> <query> [flags]
    Benchmark a single query, cold or hot, for a duration

  start search-aggregation <reference> <func> <fields> ... [flags]
    Benchmark a single aggregation, cold or hot, for a duration

  stop <id>
    Stop a running benchmark early

  compare <baseline> <comparison>
    Compare two finished runs

  list
    List benchmark runs

Run "@seqbenchbot <command> --help" for more information on a command.

@eguguchkin

Copy link
Copy Markdown
Collaborator

@seqbenchbot start search-aggregation

@seqbenchbot

seqbenchbot commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Oh-oh, @eguguchkin ('>o.o)'>!

Something went wrong and I couldn't process your request.
Please take a closer look at error message:

expected "<reference> <func> <fields> ..."

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.

3 participants