Skip to content

Replace prealloc-passing with Release()-based pooling for term postings - #2398

Closed
capemox wants to merge 1 commit into
nextfrom
bitpack-simd
Closed

capemox wants to merge 1 commit into
nextfrom
bitpack-simd

Conversation

@capemox

@capemox capemox commented Sep 16, 2026

Copy link
Copy Markdown
Member

Summary

Part of the bitpack-simd effort (zapx blevesearch/zapx#447, scorch_segment_api companion PR): replaces the prealloc-passing pattern in TermFieldReader() and prepareField() with pooled reuse.

  • rv.postings[i]/rv.iterators[i] used to be handed back in as a same-shaped "prealloc" hint on every lookup, but a recycled reader's shape is frequently wrong (a mix of 1-hit and general-encoded terms landing on the same field), so the hint was often discarded and allocated over anyway.
  • Both call sites now call releasePostings() -- a type assertion against the new, optional segment.Releasable capability -- on a value they're done with, and fetch a fresh one with prealloc left nil, letting the segment implementation's own pool decide what to hand back.
  • segment.Releasable is an opt-in capability, the same idiom as the existing segment.OptimizablePostingsIterator: values that don't implement it (e.g. the unadorned/synthetic iterators built by query optimization) make releasePostings() a no-op, unchanged from before.
  • go.mod bumped to the scorch_segment_api bitpack-simd branch, which adds Releasable plus MergeablePostingsList/MergeablePostingsIterator as optional interfaces (not required additions to PostingsList/PostingsIterator, so zapx v11-v17 keep compiling unchanged).

Test plan

  • go build ./..., go vet ./... clean
  • go test ./... clean
  • go test -race ./index/scorch/... clean

TermFieldReader() and prepareField() used to hand rv.postings[i]/
rv.iterators[i] back in as a same-shaped "prealloc" hint on every
lookup, but a recycled reader's shape is frequently wrong (a mix of
1-hit and general-encoded terms on the same field), so the hint was
often discarded and allocated over anyway.

Both call sites now release a value they're done with via
releasePostings() -- a type assertion against the new, optional
segment.Releasable capability (scorch_segment_api bitpack-simd
branch), the same opt-in idiom as segment.OptimizablePostingsIterator
-- and fetch a fresh one with prealloc left nil, letting the segment
implementation's own pool decide what to hand back. Values that don't
implement Releasable (e.g. the unadorned/synthetic iterators built by
query optimization) make this a no-op, same as before.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage is 51.716% — bitpack-simd into next. No base build found for next.

@capemox

capemox commented Sep 16, 2026

Copy link
Copy Markdown
Member Author

Putting this off for a future release -- reverting the split/pooling approach in zapx. Closing rather than merging.

@capemox capemox closed this Sep 16, 2026
@capemox
capemox deleted the bitpack-simd branch September 16, 2026 01:34
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.

2 participants