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

Implement ByteArray pool allocator && String pool #69

Open
tuhuynh27 opened this issue Dec 11, 2021 · 4 comments · Fixed by #72
Open

Implement ByteArray pool allocator && String pool #69

tuhuynh27 opened this issue Dec 11, 2021 · 4 comments · Fixed by #72
Labels
evaluation For 'Grokking Internal member' evaluation help wanted Extra attention is needed

Comments

@tuhuynh27
Copy link
Member

tuhuynh27 commented Dec 11, 2021

Issue: There is a lot of byte[] allocated when handling TCP messages:

image

It's better to have a ByteArray pool allocator so that byte[] can be reused and avoid creating massive garbage for the GC and the throughput can be even better.

For example:

ByteArrayPoolAllocator pool = ByteArrayPoolAllocator.DEFAULT
byte[10] obj = byteArrayPool.getByteArray(10);
@tuhuynh27 tuhuynh27 added the help wanted Extra attention is needed label Dec 11, 2021
@tuhuynh27 tuhuynh27 changed the title Implement ByteArray pool allocator Implement ByteArray pool allocator | String pool Dec 11, 2021
@tuhuynh27 tuhuynh27 changed the title Implement ByteArray pool allocator | String pool Implement ByteArray pool allocator && String pool Dec 11, 2021
@tuhuynh27
Copy link
Member Author

Same for String pool, we are converting byte[] to String like below:

String str = new String(byteArray);

So every conversion, a new String object is allocated.

Reference: Avoid creating 'new' String objects when converting a byte[] to String using a specific charset

@tuhuynh27
Copy link
Member Author

@the123saurav
Copy link
Contributor

Doesn't Netty provide something similar like pooled buffer?

@tuhuynh27
Copy link
Member Author

Oh yes @the123saurav Netty does have some utility for pooled object and buffer, we can utilize that

@tuhuynh27 tuhuynh27 linked a pull request Dec 13, 2021 that will close this issue
@tuhuynh27 tuhuynh27 added the evaluation For 'Grokking Internal member' evaluation label Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
evaluation For 'Grokking Internal member' evaluation help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants