-
Notifications
You must be signed in to change notification settings - Fork 54
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
Remove allocations from StringIn when returning a string #368
Conversation
Codecov Report
@@ Coverage Diff @@
## main #368 +/- ##
==========================================
- Coverage 96.29% 96.27% -0.03%
==========================================
Files 9 9
Lines 1135 1263 +128
Branches 108 124 +16
==========================================
+ Hits 1093 1216 +123
- Misses 42 47 +5
Continue to review full report at Codecov.
|
Unfortunately, this turned out to be relatively challenging.
Ideally we want This was a very frustrating PR. I have been working on and off for over a week. I am looking forward to having it behind me. |
@regadas if you have time, this is ready. Sorry it is kind of big. I recommend reading the changes to the tests first, then see if you agree that the RadixNode isn't allocating in matchOrNull, finally review During coding I was running with scalacheck doing 20k iterations to make sure I wasn't getting lucky (which is how I found so many regressions). I got it passing reliably set at 20k and then turned it back down (although we build on 3 versions so still we get lots of chances to find errors in CI). With this and #373 I would say we are ready to publish a new version. |
Hi, @johnynek! I'll have a look later today; It's not forgotten 😄 |
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.
Hi @johnynek if I didn’t miss anything this looks great! Really just a few small nit's.
matchAtOrNull
Looks good … allocation free.
Did you had time to run some Benchmarks? I'm a bit curious. I might run some on my side.
Regarding release will we include the parser string interpolator given that we are a bit on the fence with it? Tbf I haven’t thought about it that much since the last PR and your comments.
Thanks for the review @regadas I think I addressed your comments. Here are benchmarks:
It seems that the voided performance in stringIn is slightly worse, but the unvoided (where you return the captured string) is better for the smaller string case (labeled foo here). I'm actually a bit confused. In master, I think getting almost 2x faster for small sets (foo case) and 3% worse for the broad case (which is a bit unrealistic anyway) is probably worth it, but it isn't a killer slam dunk (i.e. there are trade-offs here: some a better, some are a bit worse). Last note: the current approach to implementing voiding may be suboptimal, it may be that if we implement #379 we would see more of a win on this PR as well. What do you think @regadas ? |
Hi @johnynek,
I agree with you here. TBH the fact that there's no allocation right now is a big win and I do feel that the "unrealistic" can definitely be targeted on follow-ups. This is a good first step! That said, I'm +1 in merging this. |
* checkpoint with compiling * refactor merging * use DefiniteString more * try to fix tests * get 3.0.2 passing * fix mima, improve oneOf * checkpoint * get tests passing * more tests, format, mima * remove unused code * simplify isVoided * cleanup * add isUnit * address review comments * add non-voided stringIn benchmarks
* checkpoint with compiling * refactor merging * use DefiniteString more * try to fix tests * get 3.0.2 passing * fix mima, improve oneOf * checkpoint * get tests passing * more tests, format, mima * remove unused code * simplify isVoided * cleanup * add isUnit * address review comments * add non-voided stringIn benchmarks
stringIn currently reallocates the string is returning, however, we know at the outset all possible matches, so we don't need to reallocate. This PR changes so that we return a match without allocating.
Along the way it also refactors the oneOf merging which would need a considerable refactor anyway to deal with this change. I hope the new implementation is more direct.