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

IntTree iteration produces plenty of garbage #33

Open
CodingFabian opened this issue Dec 4, 2015 · 3 comments
Open

IntTree iteration produces plenty of garbage #33

CodingFabian opened this issue Dec 4, 2015 · 3 comments

Comments

@CodingFabian
Copy link

I am currently investigating a garbage issue created by an application using pcollections a lot.
What I observed is that Iteration over an IntTree allocates plenty of Integers, as seen in below screenshot from a profiler
screen shot 2015-12-04 at 22 07 04
I see there is a comment attached to the use of "int" here:
private int key = 0; // note we use int here since this is a truly absolute key

This should be fine, the autoBoxing, which creates the objects will hit the IntegerCache for "0",
but I that we quickly leave the area of IntegerCache and create new Integer Instances.

Would it be possible to avoid this somehow?

@hrldcpr
Copy link
Owner

hrldcpr commented Dec 6, 2015

Thanks for the report, @CodingFabian!

I'm pretty sure I can change that code to avoid autoboxing entirely.

But an Entry object will still be created on every call to next(), so won't there be a lot of garbage no matter what? Or are the Integer objects worse for some reason? Does that profiling show anything about java.util.Map.Entry objects so we can compare?

Thanks!

@CodingFabian
Copy link
Author

no objects are really bad, but I assumed that it would be possible to avoid the object here. I would see more challenge in avoiding the Entry objects, that why I have not suggested it :)

@hrldcpr
Copy link
Owner

hrldcpr commented Aug 19, 2022

This could be helped by making IntTree<V> extend Entry<Integer, V> so that it never has to call new SimpleImmutableEntry<Integer, V> during iteration, it can just return itself.

This is the way that the recently-added KVTree works; seems like a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants