-
Notifications
You must be signed in to change notification settings - Fork 652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ByteBuffer: Investigate optimal allocation sizes (probably just under a power of two) #2729
Comments
See some note to consider in the related case: |
Similar to #2770 |
Maybe we could be allowed to optionally provide a malloc size strategy that could default to the current power-of-two behavior but let one provide the result from the Darwin function (or some other heuristic of we know we want an exact size as in the other case I linked to, or if we know optimal sizes for the current allocator in use eg. Jemalloc)? This would give us the ability to influence overhead. The size returned by such a closure would need to be bigger or equal to the requested size of course. |
I think this wraps into a broader question around custom allocator patterns. There's been some interest in us actually making |
Currently, ByteBuffer always allocates in powers of 2 which makes sense. But many allocators have a small amount of overhead which means the actual space reservation might be even bigger, possibly another power of two, often unnecessarily.
For example the following could happen:
allocator.buffer(capacity: 9_000)
malloc(16_384)
(power of 2)This could yield to an extra page being mapped for nothing (we only needed 9000 bytes after all). NIO's ByteBuffer should probably allocate just under the next power of two to leave some slack for the allocator in case it needs it. Needs investigation.
This becomes even more important if/when ByteBuffer is able to use tail allocations.
The text was updated successfully, but these errors were encountered: