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
Share instance of ClassTag in a ClassValue based cache #7879
Conversation
3e621d2
to
b5d7db6
Compare
Also a simpler alternative :-) Looks good. |
I'll take a look at the compiler performance (and profiles thereof) of the second commit to see if the cost of |
The profile recorded one sample (of 5966) with We could create a way to enable the old behaviour with a system property to be more conservative. I should also do a direct microbenchmark to see how the worst case looks. |
The new benchmark actually improves (slightly) with the
|
/synch |
case _ => new GenericClassTag[T](runtimeClass1) | ||
} | ||
def apply[T](runtimeClass1: jClass[_]): ClassTag[T] = runtimeClass1 match { | ||
case x if x.isPrimitive => primitiveClassTag(runtimeClass1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it better to have this logic in the computeValue
depends on the frequency of lookup etc
Ideally we could add the special values to the cache on its construction, but I can see a hook to allow that in ClassValue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds more regular, I've added a commit.
It slightly improves the lookup speed of refererence classtags.
[info] ClassTagBenchmark.lookupClassTag avgt 20 33.653 ± 0.644 ns/op
I'm also applying this technique to |
That seems ready. @retronym, squash and merge? |
And: it was originally against 2.12.x, then you moved it to 2.13, do you remember why? |
Hmm, could this prevent classes from being garbage collected? |
Ah, |
- Optimize ClassTag.apply to avoid testing for primitive classes one-by-one. - Share instance of ClassTag in a ClassValue based cache and rely on this in the compiler where we had previously hoisted hot instances.
Squashed and retargeted to 2.12.x |
/synch |
"validate-main — No corresponding job found on Jenkins. Failed to launch? Try /rebuild " looks like a bug in scabot when retargetting PRs from 2.13.x to 2.13.x. |
Thanks for the reminder. I'll forward port it this week with the subsequent patch to avoid the leak. |
Forward port proposed in #9487 |
A dynamic alternative to #7862