-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Interval: make public fields final
#4903
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
base: dev
Are you sure you want to change the base?
Conversation
The class docs already state that Interval is immutable, but this is not enforced. Followup to antlr#4901 Signed-off-by: Steven Schlansker <[email protected]>
63f2a79 to
3670527
Compare
| } | ||
| // if in middle a..x..b, split interval | ||
| if ( el>a && el<b ) { // found in this interval | ||
| int oldb = I.b; |
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.
I think this variable oldb is redundant since we already saved I.b above at line 656. Let me know if you'd like me to remove this. (I didn't, in the spirit of keeping the change minimal)
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.
Only test coverage would tell us that. Let's not touch this.
| } | ||
| // if in middle a..x..b, split interval | ||
| if ( el>a && el<b ) { // found in this interval | ||
| int oldb = I.b; |
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.
Only test coverage would tell us that. Let's not touch this.
|
@parrt blessed. |
|
I agree there is an inconsistency there, but in the back of my mind, I remember there being a reason. Perhaps @sharwell who has a young agile mind still can remember. In a nutshell, that is an insanely complicated algorithm and finally tuned implementation. We should be very careful about changing it unless there's a really good reason. :D |
In my opinion correctness and consistency matter more than performance. |
|
What's the decision here? Is there going to be a release once this change lands? |
Hey we're all very busy with our daily jobs, you might need to give this a bit more time :-) |
|
@kaby76 Hey Ken, as a mean to consolidate our confidence that this change is both useful and harmless, would you be able to test it against a significant set of grammars? |
|
Ok, will do. Let you know tomorrow or sooner if there's something unexpected. K |
|
Thanks folks. If Ken can show that it works across all of his tests then let’s go for it |
|
I'd want to see allocation benchmarks on big scenarios before moving forward here. Unfortunately, I'm not set up to run these anymore. Do we have any concrete examples of bugs in the wild caused by this? |
|
@sharwell, yes, this was the issue that led to it: jdbi/jdbi#2898 |
@sharwell If that helps, your C# implementation uses readonly fields. |
|
Sorry for taking a bit of time, but I wanted to be sure. The PR causes no regressions in any of the 370 grammars in grammars-v4. For most grammars, there was no statistical change in speed with the PR. However, there was for a few grammars, all slightly faster. For plsql, there was a speed up of 2% (sample size=20, two-sided t-test, t-statistic 8.97, df=38, p=6.3e-11). I made sure to make sure no bias in order of testing the PR versus control. |
|
@sharwell that sounds like pretty good evidence. What do you think? I'm always nervous about these kind of changes, but it seems to fix a bug and not affect performance. |
|
Thanks to @kaby76 for runnin all those tests! |
|
I reviewed again and noticed that the only mutations of these fields occurred in
It doesn't hurt, but I have to keep in mind that the ANTLR 4 C# optimized target was constructed a bit differently from my old work on the ANTLR 3 C# target. I missed a few details during the initial conversion (e.g. Interval and some tokens could have been structs) and my dedication to avoiding breaking changes caused some of the items to stay indefinitely. I was more focused on algorithm improvements for ANTLR 4 and somewhat less on micro-optimizations. |
The class docs already state that Interval is immutable, but this is not enforced.
Followup to #4901
I tried to fix up existing sites where this supposedly immutable class is mutated, to instead replace with a new value.