Skip to content

Simplify and Speed up some Compression Usage (#60953)#61008

Merged
original-brownbear merged 1 commit intoelastic:7.xfrom
original-brownbear:60953-7.x
Aug 12, 2020
Merged

Simplify and Speed up some Compression Usage (#60953)#61008
original-brownbear merged 1 commit intoelastic:7.xfrom
original-brownbear:60953-7.x

Conversation

@original-brownbear
Copy link
Copy Markdown
Contributor

Use thread-local buffers and deflater and inflater instances to speed up
compressing and decompressing from in-memory bytes.
Not manually invoking end() on these should be safe since their off-heap memory
will eventually be reclaimed by the finalizer thread which should not be an issue for thread-locals
that are not instantiated at a high frequency.
This significantly reduces the amount of byte copying and object creation relative to the previous approach
which had to create a fresh temporary buffer (that was then resized multiple times during operations), copied
bytes out of that buffer to a freshly allocated byte[], used 4k stream buffers needlessly when working with
bytes that are already in arrays (writeTo handles efficient writing to the compression logic now) etc.

Relates #57284 which should be helped by this change to some degree.
Also, I expect this change to speed up mapping/template updates a little as those make heavy use of these
code paths.

backport of #60953

Use thread-local buffers and deflater and inflater instances to speed up
compressing and decompressing from in-memory bytes.
Not manually invoking `end()` on these should be safe since their off-heap memory
will eventually be reclaimed by the finalizer thread which should not be an issue for thread-locals
that are not instantiated at a high frequency.
This significantly reduces the amount of byte copying and object creation relative to the previous approach
which had to create a fresh temporary buffer (that was then resized multiple times during operations), copied
bytes out of that buffer to a freshly allocated `byte[]`, used 4k stream buffers needlessly when working with
bytes that are already in arrays (`writeTo` handles efficient writing to the compression logic now) etc.

Relates #57284 which should be helped by this change to some degree.
Also, I expect this change to speed up mapping/template updates a little as those make heavy use of these
code paths.
@original-brownbear original-brownbear added :Core/Infra/Core Core issues without another label backport labels Aug 12, 2020
@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Core)

@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Aug 12, 2020
@original-brownbear original-brownbear merged commit 32423a4 into elastic:7.x Aug 12, 2020
@original-brownbear original-brownbear deleted the 60953-7.x branch August 12, 2020 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport :Core/Infra/Core Core issues without another label Team:Core/Infra Meta label for core/infra team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants