Skip to content
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

byte-buffer: use malloc_good_size on Darwin to allocate memory #3066

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

natikgadzhi
Copy link
Contributor

Motivation:

With this change, on Darwin, ByteBuffer will use less memory, and memory allocations will be aligned with pages better, hopefully improving memory efficiency.

This is part 1 of #2770. The next step is to figure out better allocation strategy for Libc, Musl, etc.

Modifications:

  • Introduces a new internal helper method to _Storage that returns the optimal storage size
  • Uses that to malloc capacity.
  • A few tests to verify allocation sizes.

Motivation:

With this change, on Darwin, ByteBuffer will use less memory, and memory
allocations will be aligned with pages better, hopefully improving memory efficiency.

Modifications:

- Introduces a new internal helper method to `_Storage` that returns the optimal storage size
- Uses that to malloc capacity.
Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Mostly great, one quick note!


@testable import NIOCore

#if canImport(Darwin)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make these tests cross-platform by redefining the logic here. We can just have an abstraction function that is essentially equivalent to mallocSize, but allows us to validate that that's what we're actually using.

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