-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Remove Interval internal cache #4902
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
Conversation
The cache is not thread safe, but it was used in the multithreaded context, making it possible for the `Interval.of` method to return invalid values. Signed-off-by: lukasz-stec <[email protected]>
|
Hey, thanks for this. Have you considered the option of prepopulating the cache ? Sounds cheap and likely to preserve performance ? |
Yeah, it is one of the options I included in #4901. I think it is not a bad idea if we want to keep the cache. The memory overhead would be small. The same goes for class initialization. The alternative is to make the Interval fields final. That said, I would be surprised if the cache brings noticeable performance benefits because the allocation and gc of short-lived objects in Java is cheap, and it is likely that in many places the construction of Interval will be inlined and “scalar replaced” anyway, so the allocation is avoided entirely. |
|
I guess you'd need to measure performance rather than make assumptions? |
|
Making the fields final is also certainly helpful, although I doubt we have any code writing to them ? If we do, it should be changed (that would deserve a separate PR) |
|
As far as I see, the performance probably might be improved if use the primitive |
Are there any benchmarks that I can run? I'm new to the codebase so any help is appriciated.
If we make the fields final, it should fix the issue, because then the Interval instance is published safely. According to Java memory model, final fields need to be initialized before the reference to the object is available, unless it is leaked from the constructor. |
|
The scientific method should be employed rather than guessing. Here is a graph comparing the effect of the PR for two SQL grammars (mysql and plsql). I didn't do a t-test because these two grammars appeared to have opposite speed-up effects. For the mysql, the PR appears to have no statistical effect, while for plsql, it does, although quite small. I may write a Bash/Octave script that goes through all grammars in grammars-v4 and determines which grammars exhibit statistical differences in performance for the PR. plsql-before.txt |
|
I prepared a small JMH benchmark for the Interval creation directly (code and full results below). The results show that if the |
|
Thanks for this. Can you rerun it with |
|
|
Thanks for the clarification. |
|
I've tested this against the 377 grammars in grammars-v4 multiple times, in different orders to eliminate bias, and double-checked everything. The cache has no statistical benefit for the Java target. While |
|
thanks folks! |
|
Thanks everyone for looking at this. Does it make sense to make the |
|
Yes it does, please file a dedicated PR for this. |
|
Ah, it turns out that |
|
I think we should proceed with caution here. I’m certain there’s a good reason we did that even if it makes no sense ha ha |
I agree we should proceed with caution. Given the performance benchmark though, I suspect the original reason was good at the time but maybe no longer good enough. |
The cache is not thread safe, but it was used in the multithreaded context, making it possible for the
Interval.ofmethod to return invalid values.This is a proposed fix for the #4901