-
Notifications
You must be signed in to change notification settings - Fork 268
perf: Optimize lpad/rpad to remove unnecessary memory allocations per element #2963
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
|
@coderfender fyi |
|
Thank you very much for the optimization @andygrove |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2963 +/- ##
============================================
+ Coverage 56.12% 59.62% +3.49%
- Complexity 976 1375 +399
============================================
Files 119 167 +48
Lines 11743 15488 +3745
Branches 2251 2567 +316
============================================
+ Hits 6591 9234 +2643
- Misses 4012 4956 +944
- Partials 1140 1298 +158 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| let string_array = as_generic_string_array::<T>(array)?; | ||
|
|
||
| // Pre-compute pad characters once to avoid repeated iteration | ||
| let pad_chars: Vec<char> = pad_string.chars().collect(); |
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.
👍
| ); | ||
|
|
||
| // Reusable buffer to avoid per-element allocations | ||
| let mut buffer = String::new(); |
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.
we can prob to the buffer fixed size?
String::with_capacity(rpad_length);
?
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.
Updated both of these. Thanks!
| ); | ||
|
|
||
| // Reusable buffer to avoid per-element allocations | ||
| let mut buffer = String::new(); |
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.
same?
comphead
left a comment
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 @andygrove good benches
Which issue does this PR close?
Closes #.
Rationale for this change
What changes are included in this PR?
How are these changes tested?