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

Use ClassValue to store ThreadLocal call depth #1528

Merged
merged 3 commits into from Jun 3, 2020

Conversation

richardstartin
Copy link
Member

@bantonsson can you try this?

@richardstartin richardstartin requested a review from a team as a code owner June 3, 2020 13:20
@bantonsson
Copy link
Contributor

Since I'm mostly looking at the memory, it obviously shaves off the last % of the HashMap$Node, and I can't see anything else popping up. 👍

@richardstartin richardstartin changed the title ClassValue call depth experiment Use ClassValue to store ThreadLocal call depth Jun 3, 2020
@richardstartin richardstartin force-pushed the richardstartin/classvalue branch 2 times, most recently from be73bf9 to f183719 Compare June 3, 2020 14:50
@richardstartin
Copy link
Member Author

I am under the impression that ClassValue.get is more efficient than HashMap.get(Class<?>) but haven't measured it, and in most instrumentations we would expect there to be fewer classes with tracked depths than the default size of a HashMap, so I expect this should use less heap. In any case, the change has the commit from #1527 so will apply cleanly if we want to do this later and merge that now.

}

public static void reset(final Class<?> k) {
TLS.get(k).remove();
Copy link
Contributor

Choose a reason for hiding this comment

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

Crazy idea, but instead of removing, should we just reset the depth to 0?

Copy link
Member Author

Choose a reason for hiding this comment

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

@bantonsson what do you think? On the one hand, this is a recipe for a memory leak with non cached threads, on the other it's a parsimonious approach when threads are cached.

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually think that it's fine to leave the Depth in there. I mean if people are creating threads and they don't run to completion, they have other issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@bantonsson
Copy link
Contributor

I agree that this is probably better than the HashMap version. I think this should go in.

@tylerbenson
Copy link
Contributor

Let's merge both PRs since this one builds off the other one. (But merge this one last.)

@tylerbenson tylerbenson added the tag: performance Performance related changes label Jun 3, 2020
@richardstartin
Copy link
Member Author

@tyler we can just merge this because it has @bantonsson's commit

Copy link
Contributor

@bantonsson bantonsson left a comment

Choose a reason for hiding this comment

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

👍

@richardstartin richardstartin merged commit 198e7db into master Jun 3, 2020
@richardstartin richardstartin deleted the richardstartin/classvalue branch June 3, 2020 15:50
@github-actions github-actions bot added this to the 0.54.0 milestone Jun 3, 2020
@dougqh
Copy link
Contributor

dougqh commented Jun 3, 2020

I am under the impression that ClassValue.get is more efficient than HashMap.get(Class<?>) but haven't measured it, and in most instrumentations we would expect there to be fewer classes with tracked depths than the default size of a HashMap, so I expect this should use less heap. In any case, the change has the commit from #1527 so will apply cleanly if we want to do this later and merge that now.

I haven't used ClassValue myself previously. But from Googling and reviewing the ClassValue, it does look promising. Also nicely handles class unloading from what I've read. Maybe, we should be using it more broadly. Although in many places, we really need the equivalent of a ClassLoaderValue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tag: performance Performance related changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants