Skip to content

perf: implement batch execution AND/OR/NAND - #479

Merged
cheb0 merged 8 commits into
329-lid-bitmapsfrom
329-batch-execution
Aug 25, 2026
Merged

perf: implement batch execution AND/OR/NAND#479
cheb0 merged 8 commits into
329-lid-bitmapsfrom
329-batch-execution

Conversation

@cheb0

@cheb0 cheb0 commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Description

Batch execution allows to iterate over inverted index batch by batch instead of lid by lid.

Batches are either of slice or roaring bitmap type. When batches are intersected/unioned they are converted to bitmaps.

Enabling

  • query AST should suffice (AND/OR/AND NOT/range)
  • range node can have at most 5 tids resolved
  • iteration cost is evaluated and must be at least of configured number (freqs are required in fraction)

Iteration cost evaluation allows to enable batching when it's really worth it. In that case we know some good amount of LID blocks will be directly used as bitmaps and not be converted.

Results

  • Searches - I'd say most queries are unaffected except those which iterate over millions of postings.
Query env Total cold, ms   hot, ms   cold (branch), ms   hot (branch), ms   cold diff hot diff
service:large-service prod 220827 16.32 ±3.45 0.54 ±0.10 16.81 ±6.27 0.7 ±0.09 3% 29.6%
service:large-service AND level:6 prod 111809 24.9 ±3.25 6.75 ±0.12 18.42 ±1.76 2.56 ±0.49 -26% -62.1%
service:small-service AND level:3 prod 349 35.75 ±1.03 2.07 ±0.13 38.12 ±1.89 2.37 ±0.12 6.6% 14.5%
service:srv* AND level:[0 to 3] prod 214 51.54 ±1.94 8.49 ±0.15 51.67 ±1.54 9.43 ±0.19 0.3% 11.1%
request_host:large-host AND response_status:200 lb 1058473 47.01 ±2.74 21.16 ±0.36 22.23 ±1.69 5.09 ±0.25 -52.7% -75.9%
request_host:large-host AND response_status:500 lb 2 14.91 ±0.33 0.31 ±0.03 16.62 ±2.67 0.48 ±0.15 11.5% 54.8%
request_host:large-host AND request_method:POST AND geoip_country:RU lb 485486 66.71 ±5.18 30.11 ±0.17 25.66 ±2.96 5.18 ±0.70 -61.5% -82.8%
(response_status:504 or response_status:502) and (cluster_name:cl1 or cluster_name:cl2) lb 2996 49.42 ±2.28 2.2 ±0.06 44.76 ±2.00 1.66 ±0.03 -9.4% -24.5%
k8s_service_name:medium-service and request_host:medium-host lb 357675 21.1 ±0.66 5.31 ±0.13 17.55 ±1.31 2.02 ±0.10 -16.8% -62%
(request_host:small-host or request_host:small-host2) and hostname:some-server lb 25 19.72 ±0.69 0.42 ±0.03 18.66 ±0.73 0.45 ±0.04 -5.4% 7.1%
NOT response_status:200 lb 192352 32.85 ±3.50 13.19 ±0.20 45.88 ±2.08 27.34 ±0.72 39.7% 107.3%
request_host:large-host AND NOT response_status:200 lb 6747 69.38 ±2.03 17.32 ±0.15 22.18 ±2.43 4.22 ±1.12 -68% -75.6%
request_host:small-host AND NOT (request_method:post or request_method:get) lb 0 43.58 ±2.40 17.62 ±0.26 17.32 ±0.75 2.77 ±0.25 -60.3% -84.3%
  • Histograms - behave like searches but improvement is lower since we read MIDs
Query env Total cold, ms   hot, ms   cold (branch), ms   hot (branch), ms   cold diff hot diff
service:large-service AND level:[4 to 6] | hist 60s prod 218423 95.5 ±3.71 12.59 ±0.41 87.72 ±5.60 6.97 ±1.43 -8.1% -44.6%
request_host:large-host AND response_status:200 | hist 60s lb 1058473 136.62 ±5.49 27.33 ±1.49 112.97 ±4.36 11.1 ±0.98 -17.3% -59.4%
  • Aggs - Mostly aggs do not use batching, but there is an overhead from allocating batches in LID cursors.
Query env Total cold, ms   hot, ms   cold (branch), ms   hot (branch), ms   cold diff hot diff
|service:marketing-actions-api | by k8s_pod prod 112107 256.22 ±4.80 173.08 ±3.03 294.39 ±29.50 216.32 ±24.66 14.9% 25%
request_host:api.ozon.ru | by remote_addr lb 1065220 2307.86 ±107.43 2148.07 ±127.33 2830.23 ±473.64 2591.46 ±388.58 22.6% 20.6%

Major problems

There are problems I found while working on batch execution. Can be partially addressed in future.

  • LIDBatch - interface dispatch overhead is now present on inverted index which has partially affected hot queries performance.
  • roaring bitmap doesn't have NextGEQ (single function)
  • Batches can grow very large, i.e. level:[5 to 7] (nodeOrBatchedMulti) can yield a large batch of size more than LID block. Truncating a batch can cost CPU and increase query execution time.
  • Batches needs to be allocated
  • Batch truncation takes CPU time. Current execution model is same as for LIDs which means we need truncation when do OR/AND NOT. It's possible to redo the model with full materialization. It will sacrifice early exit and block skipping but can be more performant with current inverted index sort order.

  • I have read and followed all requirements in CONTRIBUTING.md;
  • I used LLM/AI assistance to make this pull request;

@cheb0
cheb0 force-pushed the 329-batch-execution branch 3 times, most recently from 5891414 to 85278eb Compare July 29, 2026 08:49
@cheb0
cheb0 marked this pull request as ready for review July 31, 2026 05:59
@cheb0
cheb0 force-pushed the 329-batch-execution branch from 85278eb to c5804e0 Compare July 31, 2026 09:10
@eguguchkin eguguchkin added this to the v0.77.0 milestone Aug 3, 2026
@dkharms dkharms added the performance Features or improvements that positively affect seq-db performance label Aug 6, 2026
@cheb0
cheb0 force-pushed the 329-batch-execution branch from c5804e0 to 28330f0 Compare August 13, 2026 05:27
@cheb0 cheb0 changed the title perf: batch execution AND/OR/NAND perf: implement batch execution AND/OR/NAND Aug 13, 2026
@cheb0
cheb0 force-pushed the 329-batch-execution branch from 28330f0 to 1116aa2 Compare August 13, 2026 05:36
@codecov-commenter

codecov-commenter commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.11502% with 137 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.40%. Comparing base (eafac32) to head (b5c5907).

Files with missing lines Patch % Lines
node/node_static.go 31.25% 29 Missing and 4 partials ⚠️
frac/processor/batch_eval_tree.go 73.77% 22 Missing and 10 partials ⚠️
node/util.go 48.57% 18 Missing ⚠️
node/node_or.go 77.41% 13 Missing and 1 partial ⚠️
frac/processor/search.go 87.50% 5 Missing and 5 partials ⚠️
frac/active_index.go 38.46% 8 Missing ⚠️
cmd/seq-db/seq-db.go 0.00% 6 Missing ⚠️
node/batch_ops.go 94.91% 3 Missing and 3 partials ⚠️
frac/sealed_index.go 88.57% 2 Missing and 2 partials ⚠️
node/batch.go 95.65% 1 Missing and 1 partial ⚠️
... and 2 more
Additional details and impacted files
@@                 Coverage Diff                 @@
##           329-lid-bitmaps     #479      +/-   ##
===================================================
+ Coverage            71.21%   71.40%   +0.19%     
===================================================
  Files                  235      238       +3     
  Lines                19403    19924     +521     
===================================================
+ Hits                 13818    14227     +409     
- Misses                4532     4628      +96     
- Partials              1053     1069      +16     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown
Contributor

🔴 Performance Degradation

Some benchmarks have degraded compared to the previous run.
Click on Show table button to see full list of degraded benchmarks.

Show table
Name Previous Current Ratio Verdict
Indexer-4 a73114 c61b6a
678752766.00 B/op 762523594.00 B/op 1.12 🔴
Sealing_NoSort-4 a73114 c61b6a
5335.00 allocs/op 8308.00 allocs/op 1.56 🔴
Sealing_WithSort-4 a73114 c61b6a
5389.00 allocs/op 8381.00 allocs/op 1.56 🔴

@eguguchkin
eguguchkin requested review from forshev and removed request for dkharms August 20, 2026 08:34
Comment thread config/config.go Outdated
Comment thread node/util.go Outdated
Comment thread node/node.go Outdated
Comment thread frac/processor/search.go Outdated
Comment thread frac/sealed_index.go
Comment thread frac/sealed_index.go
Comment thread node/batch.go
Comment thread node/node_static.go
Comment thread node/node_static.go
Comment thread node/util.go Outdated
Comment thread frac/processor/batch_eval_tree.go
Comment thread frac/processor/batch_eval_tree.go
Comment thread frac/processor/batch_eval_tree.go
Comment thread frac/processor/batch_eval_tree.go
@cheb0
cheb0 force-pushed the 329-batch-execution branch from d2eef53 to f5b72de Compare August 24, 2026 12:19
@github-actions

Copy link
Copy Markdown
Contributor

🔴 Performance Degradation

Some benchmarks have degraded compared to the previous run.
Click on Show table button to see full list of degraded benchmarks.

Show table
Name Previous Current Ratio Verdict
Sealing_NoSort-4 a73114 d04bce
24958384.00 B/op 28386656.00 B/op 1.14 🔴
5335.00 allocs/op 8332.00 allocs/op 1.56 🔴
Sealing_WithSort-4 a73114 d04bce
5389.00 allocs/op 8402.00 allocs/op 1.56 🔴

@github-actions

Copy link
Copy Markdown
Contributor

🔴 Performance Degradation

Some benchmarks have degraded compared to the previous run.
Click on Show table button to see full list of degraded benchmarks.

Show table
Name Previous Current Ratio Verdict
Sealing_NoSort-4 a73114 4f37ec
24958384.00 B/op 28342896.00 B/op 1.14 🔴
5335.00 allocs/op 8330.00 allocs/op 1.56 🔴
Sealing_WithSort-4 a73114 4f37ec
5389.00 allocs/op 8402.00 allocs/op 1.56 🔴

@cheb0
cheb0 force-pushed the 329-batch-execution branch from 87ac241 to f15648a Compare August 24, 2026 17:27
@github-actions

Copy link
Copy Markdown
Contributor

🔴 Performance Degradation

Some benchmarks have degraded compared to the previous run.
Click on Show table button to see full list of degraded benchmarks.

Show table
Name Previous Current Ratio Verdict
Sealing_NoSort-4 365d02 d56032
25001152.00 B/op 28389824.00 B/op 1.14 🔴
5344.00 allocs/op 8340.00 allocs/op 1.56 🔴
Sealing_WithSort-4 365d02 d56032
40320160.00 B/op 44815744.00 B/op 1.11 🔴
5414.00 allocs/op 8413.00 allocs/op 1.55 🔴

@github-actions

Copy link
Copy Markdown
Contributor

🔴 Performance Degradation

Some benchmarks have degraded compared to the previous run.
Click on Show table button to see full list of degraded benchmarks.

Show table
Name Previous Current Ratio Verdict
Indexer-4 365d02 d56032
683995073.00 B/op 764280850.00 B/op 1.12 🔴
Sealing_NoSort-4 365d02 d56032
25001152.00 B/op 28389264.00 B/op 1.14 🔴
5344.00 allocs/op 8335.00 allocs/op 1.56 🔴
Sealing_WithSort-4 365d02 d56032
5414.00 allocs/op 8391.00 allocs/op 1.55 🔴

@github-actions

Copy link
Copy Markdown
Contributor

🔴 Performance Degradation

Some benchmarks have degraded compared to the previous run.
Click on Show table button to see full list of degraded benchmarks.

Show table
Name Previous Current Ratio Verdict
Indexer-4 365d02 e7ccc3
683995073.00 B/op 776488737.00 B/op 1.14 🔴
Sealing_NoSort-4 365d02 e7ccc3
25001152.00 B/op 28377568.00 B/op 1.14 🔴
5344.00 allocs/op 8340.00 allocs/op 1.56 🔴
Sealing_WithSort-4 365d02 e7ccc3
5414.00 allocs/op 8395.00 allocs/op 1.55 🔴

@github-actions

Copy link
Copy Markdown
Contributor

🔴 Performance Degradation

Some benchmarks have degraded compared to the previous run.
Click on Show table button to see full list of degraded benchmarks.

Show table
Name Previous Current Ratio Verdict
Indexer-4 365d02 29405b
683995073.00 B/op 773719496.00 B/op 1.13 🔴
Sealing_NoSort-4 365d02 29405b
5344.00 allocs/op 8321.00 allocs/op 1.56 🔴
Sealing_WithSort-4 365d02 29405b
5414.00 allocs/op 8406.00 allocs/op 1.55 🔴

@cheb0
cheb0 merged commit 9e0f6a9 into main Aug 25, 2026
8 checks passed
@cheb0
cheb0 deleted the 329-batch-execution branch August 25, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Features or improvements that positively affect seq-db performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants