Commit 4a41173
authored
perf: Optimize
## Which issue does this PR close?
- Closes #22170.
## Rationale for this change
This PR refactors and optimizes the `translate` UDF. In particular, we
switch to using the new bulk-NULL string builders, avoiding per-row NULL
computation, and avoid an intermediate string copy by using
`append_with` / `append_byte_map`.
Benchmarks (Arm64):
Scalar (scalar_from_to)
- size=1024, str_len=8: 13.6 µs → 8.5 µs (-37.5%)
- size=1024, str_len=32: 26.2 µs → 20.6 µs (-21.4%)
- size=1024, str_len=128: 87.9 µs → 68.9 µs (-21.6%)
- size=1024, str_len=1024: 572.9 µs → 531.1 µs (-7.3%)
- size=4096, str_len=8: 51.6 µs → 31.4 µs (-39.1%)
- size=4096, str_len=32: 103.1 µs → 79.8 µs (-22.6%)
- size=4096, str_len=128: 341.1 µs → 273.4 µs (-19.8%)
- size=4096, str_len=1024: 2.3 ms → 2.1 ms (-8.7%)
Array — ASCII (array_from_to)
- size=1024, str_len=8: 50.6 µs → 21.2 µs (-58.1%)
- size=1024, str_len=32: 106.5 µs → 26.7 µs (-74.9%)
- size=1024, str_len=128: 265.4 µs → 59.9 µs (-77.4%)
- size=1024, str_len=1024: 1760.8 µs → 797.1 µs (-54.7%)
- size=4096, str_len=8: 211.4 µs → 84.3 µs (-60.1%)
- size=4096, str_len=32: 435.2 µs → 120.6 µs (-72.3%)
- size=4096, str_len=128: 1079.0 µs → 487.6 µs (-54.8%)
- size=4096, str_len=1024: 7.2 ms → 3.2 ms (-55.6%)
Array — non-ASCII (array_from_to_non_ascii)
- size=1024, str_len=8: 71.2 µs → 68.6 µs (-3.7%)
- size=1024, str_len=32: 228.8 µs → 236.9 µs (+3.5%)
- size=1024, str_len=128: 880.5 µs → 881.4 µs (+0.1%)
- size=1024, str_len=1024: 6.7 ms → 6.7 ms (+0.6%)
- size=4096, str_len=8: 375.5 µs → 376.6 µs (+0.3%)
- size=4096, str_len=32: 1041.2 µs → 1079.6 µs (+3.7%)
- size=4096, str_len=128: 3.5 ms → 3.6 ms (+2.9%)
- size=4096, str_len=1024: 27.0 ms → 26.8 ms (-0.7%)
## What changes are included in this PR?
* Switch from using the Rust StringBuilders to our new bulk-NULL string
builders
* Switch from per-row NULL checks to computing the NULL bitmaps with
`NullBuffer::union_many`
* Use `append_with` and `append_byte_map` rather than `append_value`,
which avoids an intermediate scratch buffer
* Refactor lookup table code to use a single `TranslationTable` enum
* Add a benchmark for the "varying `from`/`to`, Unicode strings" case
* Add a unit test
## Are these changes tested?
Yes; new test added.
## Are there any user-facing changes?
No.translate to use new bulk-NULL string builders (#22171)1 parent cbebc6f commit 4a41173
2 files changed
Lines changed: 316 additions & 149 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
30 | 57 | | |
31 | 58 | | |
32 | 59 | | |
| |||
42 | 69 | | |
43 | 70 | | |
44 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
45 | 91 | | |
46 | 92 | | |
47 | 93 | | |
| |||
91 | 137 | | |
92 | 138 | | |
93 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
94 | 151 | | |
95 | 152 | | |
96 | 153 | | |
| |||
0 commit comments