Skip to content

Reduce allocations in AsyncTaskIndexService#142290

Merged
DaveCTurner merged 5 commits intoelastic:mainfrom
DaveCTurner:2026/02/11/AsyncTaskIndexService-INITIAL_BUFFER
Feb 13, 2026
Merged

Reduce allocations in AsyncTaskIndexService#142290
DaveCTurner merged 5 commits intoelastic:mainfrom
DaveCTurner:2026/02/11/AsyncTaskIndexService-INITIAL_BUFFER

Conversation

@DaveCTurner
Copy link
Copy Markdown
Member

Today we create our buffer with a zero expectedSize which prefers to
repeatedly allocate with new byte[] instead of using recycled pages
until the buffer contents get big enough.

With this commit we always allocate a (recycled) whole page instead,
avoiding all those allocations.

Today we create our buffer with a zero `expectedSize` which prefers to
repeatedly allocate with `new byte[]` instead of using recycled pages
until the buffer contents get big enough.

With this commit we always allocate a (recycled) whole page instead,
avoiding all those allocations.
@DaveCTurner DaveCTurner added >non-issue :StorageEngine/ES|QL Timeseries / metrics / PromQL / logsdb capabilities in ES|QL v9.4.0 labels Feb 11, 2026
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

Copy link
Copy Markdown
Contributor

@alex-spies alex-spies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks reasonable to me, but I'd defer to someone who's got more experience with the async indices and our page recycling to approve.

@alex-spies alex-spies requested a review from nik9000 February 11, 2026 11:11
Copy link
Copy Markdown
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got the experience with the recycler. This will keep us from allocating a byte array most of the time. Looks good to me.

@DaveCTurner DaveCTurner enabled auto-merge (squash) February 12, 2026 20:43
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Feb 13, 2026
This caught me out in elastic#140365: we actually don't use the slow-growth
behaviour by default with a `ReleasableBytesStreamOutput`, you have to
ask for it. But we do ask for it sometimes, so this commit fixes the
docs and one of the places where we do.

Relates elastic#142290, which fixes another case of this.
@DaveCTurner
Copy link
Copy Markdown
Member Author

I just noticed that you get the same behaviour, but needing less explanation, if you just drop the expectedSize parameter entirely. That's what we do basically everywhere else. I adjusted the docs in #142451

@DaveCTurner DaveCTurner merged commit 0d0c29a into elastic:main Feb 13, 2026
35 checks passed
sidosera pushed a commit to sidosera/elasticsearch that referenced this pull request Feb 13, 2026
Today we create our buffer with a zero `expectedSize` which prefers to
repeatedly allocate with `new byte[]` instead of using recycled pages
until the buffer contents get big enough.

With this commit we always allocate a (recycled) whole page instead,
avoiding all those allocations.
@DaveCTurner DaveCTurner deleted the 2026/02/11/AsyncTaskIndexService-INITIAL_BUFFER branch February 14, 2026 05:06
DaveCTurner added a commit that referenced this pull request Feb 19, 2026
…42451)

This caught me out in #140365: we actually don't use the slow-growth
behaviour by default with a `ReleasableBytesStreamOutput`, you have to
ask for it. But we do ask for it sometimes, so this commit fixes the
docs and one of the places where we do.

Relates #142290, which fixes another case of this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>non-issue :StorageEngine/ES|QL Timeseries / metrics / PromQL / logsdb capabilities in ES|QL Team:StorageEngine v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants