-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Optimize performance of substr_index and add tests #9973
Conversation
CI failure seems unrelated:
|
Agreed -- I restarted the job |
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.
Looks nice a nice improvement to me -- thank you @kevinmingtarja 🙏
I left a suggestion for how to make it even better, but I also think we can do that as a follow on PR
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.
Thank you @kevinmingtarja -- this is looking really close. I think the null/no match cases aren't quite right but it should be easily fixable
919cc06
to
421f6d9
Compare
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.
Thanks @kevinmingtarja -- this looks really nice 🙏
FYI @Omega359 |
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.
lgtm thanks @kevinmingtarja I really like the improvement
Nice work! If there is another function that you think could use a look at for performance I'll be happy to write the benchmark for testing. |
🚀 |
Which issue does this PR close?
Closes #9890
Rationale for this change
We were using dynamic dispatch when deciding whether to do
string.split()
orstring.rsplit()
(depending on thecount
argument) because the exact type of iterator is not known at compile time, plus it allocates memory on the heap for the boxed iterator, which introduces considerable overhead.Instead, we can avoid doing this and handle the two cases with an if else statement, which removes that overhead and potentially enable further optimizations by the compiler.
Another major overhead is pointed to in #9973 (comment). Instead, we can avoid
String
creation at every iteration ofmap
by usingStringBuilder
to build the output.Benchmarks
substr_index_array_array_1000 time: [57.082 µs 57.407 µs 57.770 µs] change: [-53.118% -52.034% -51.077%] (p = 0.00 < 0.05) Performance has improved. Found 6 outliers among 100 measurements (6.00%) 2 (2.00%) high mild 4 (4.00%) high severe
No more time wasted on
malloc
andfree
now if we see the flamegraph:What changes are included in this PR?
Are these changes tested?
Yes. I added new unit tests as well for
substr_index
since there were none before.Are there any user-facing changes?