-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Optimize splitPart scalar function to reduce allocation #17660
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: master
Are you sure you want to change the base?
Conversation
| * TODO: Revisit if index should be one-based (both Presto and Postgres use one-based index, which starts with 1) | ||
| * @param input | ||
| * @param delimiter | ||
| * @param input the input String to be split into parts. |
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.
copied verbatim from the the overloaded splitPart function below to keep in sync.
33336f1 to
5a2b4f1
Compare
| {"org.apache.pinot.common.function", ".", 3, 3, "common", "null"}, | ||
| {"+++++", "+", 0, 100, "", ""}, | ||
| {"+++++", "+", 1, 100, "null", "null"}, | ||
| {"+++++org++apache++", "", 1, 100, "null", "null"}, |
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.
These were missing cases I added to validate identical behavior to previous version
| @@ -0,0 +1,160 @@ | |||
| /** | |||
| * Licensed to the Apache Software Foundation (ASF) under one | |||
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 can remove this if required. Added it for my own validation of the perf
Updated the splitPart function to use direct string traversal instead of allocating a full String[] array, significantly reducing memory pressure in high-throughput query scenarios. Performance improvements: - Space complexity: O(n) → O(1) - Time complexity: O(n) for both implementations Added JMH benchmarks to demonstrate improvements and regressions. The primary regression is in the backward index case with a large index value. This is the uncommon case and maybe worth the tradeoff since the memory allocation in the common case is now significantly reduced.
5a2b4f1 to
24644cf
Compare
Optimized the splitPart function to use direct string traversal instead of allocating a full String[] array, significantly reducing memory pressure in high-throughput query scenarios.
Performance improvements:
Added JMH benchmarks to demonstrate improvements and regressions. The primary regression is in the backward index case so I added
splitPartNegativeIdxSingleCharDelim(b4272e2) which increases complexity but makes the kernel much fasterAddresses #17362
JMH Results
Yeah, the common cases are more than 10x faster 🚀 . The original results showed a regression with
negative_index, hence b4272e2. However, this code may be harder to manage so that is the trade-off. The below results are from all commits in the PRAllocation via
-prof gc