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

Optimize AbstractListenableFuture Memory Allocations #28

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

Conversation

amcrn
Copy link

@amcrn amcrn commented Nov 6, 2017

Problem: If an empty ArrayList has addAll() invoked with a Collection
argument that has a size less than 10, the underlying elementData
Object[] is still grown to 10 via an Array copy. In the case of
AbstractListenableFuture, the number of listeners is often 0 or 1,
and AbstractListenableFuture is in the critical path, meaning this
behavior causes unnecessary GC pressure for high throughput
applications.

Therefore, this commit enhances the logic to avoid the construction
of the listener copy ArrayList and its iterator if possible, and if
not, to use the more efficient constructor vs. addAll().

Problem: If an empty ArrayList has addAll() invoked with a Collection
argument that has a size less than 10, the underlying elementData
Object[] is still grown to 10 via an Array copy. In the case of
AbstractListenableFuture, the number of listeners is often 0 or 1,
and AbstractListenableFuture is in the critical path, meaning this
behavior causes unnecessary GC pressure for high throughput
applications.

Therefore, this commit enhances the logic to avoid the construction
of the listener copy ArrayList and its iterator if possible, and if
not, to use the more efficient constructor vs. addAll().
@ingenthr ingenthr self-assigned this Mar 27, 2018
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