Repository navigation
perf: Optimize lpad, rpad for ASCII strings - #20278
Conversation
|
Benchmark results: |
f3b449e to
53b7236
Compare
880029d to
f6cc464
Compare
The previous implementation incurred the overhead of Unicode machinery,
even for the common case that both the input string and the fill string
consistent only of ASCII characters. For the ASCII-only case, we can
assume that the length in bytes equals the length in characters, and
avoid expensive graphene-based segmentation. This follows similar
optimizations applied elsewhere in the codebase.
Benchmarks indicate this is a significant performance win for ASCII-only
input (4x-10x faster) but only a mild regression for Unicode input (2-5%
slower).
Along the way:
* Combine: a few instances of `write_str(str)? + append_value("")` with
`append_value(str)`, which saves a few cycles
* Add a missing test case for truncating the input string
* Add benchmarks for Unicode input
f6cc464 to
d6c1374
Compare
|
@martin-g Is this okay to land in |
|
It is hard to tell :-/ I have to make a new full code review. |
|
@martin-g Sorry about that! The "Compare" link has a lot of extraneous changes because I rebased the branch against the latest main. If you search for "rpad.rs" you can see the only changes I made to the PR itself: I just noticed a few other spots where we can combine On rebasing in general, that's good to know! I've previously worked mostly on projects that use a more rebase-centric workflow. I'm happy to avoid unnecessary rebases in the future. |
Co-authored-by: Martin Grigorov <[email protected]>
Per Martin Grigorov.
|
Thanks @neilconway & @martin-g 🚀 |
The previous implementation incurred the overhead of Unicode machinery,
even for the common case that both the input string and the fill string
consistent only of ASCII characters. For the ASCII-only case, we can
assume that the length in bytes equals the length in characters, and
avoid expensive graphene-based segmentation. This follows similar
optimizations applied elsewhere in the codebase.
Benchmarks indicate this is a significant performance win for ASCII-only
input (4x-10x faster) but only a mild regression for Unicode input (2-5%
slower).
Along the way:
* Combine: a few instances of `write_str(str)? + append_value("")` with
`append_value(str)`, which saves a few cycles
* Add a missing test case for truncating the input string
* Add benchmarks for Unicode input
## Which issue does this PR close?
- Closes apache#20277.
## Are these changes tested?
Covered by existing tests. Added new benchmarks for Unicode inputs.
## Are there any user-facing changes?
No.
---------
Co-authored-by: Martin Grigorov <[email protected]>
The previous implementation incurred the overhead of Unicode machinery, even for the common case that both the input string and the fill string consistent only of ASCII characters. For the ASCII-only case, we can assume that the length in bytes equals the length in characters, and avoid expensive graphene-based segmentation. This follows similar optimizations applied elsewhere in the codebase.
Benchmarks indicate this is a significant performance win for ASCII-only input (4x-10x faster) but only a mild regression for Unicode input (2-5% slower).
Along the way:
write_str(str)? + append_value("")withappend_value(str), which saves a few cyclesWhich issue does this PR close?
Are these changes tested?
Covered by existing tests. Added new benchmarks for Unicode inputs.
Are there any user-facing changes?
No.