Skip to content

perf: Optimize translate to use new bulk-NULL string builders#22171

Open
neilconway wants to merge 3 commits into
apache:mainfrom
neilconway:neilc/perf-translate-builder
Open

perf: Optimize translate to use new bulk-NULL string builders#22171
neilconway wants to merge 3 commits into
apache:mainfrom
neilconway:neilc/perf-translate-builder

Conversation

@neilconway
Copy link
Copy Markdown
Contributor

@neilconway neilconway commented May 14, 2026

Which issue does this PR close?

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.

@github-actions github-actions Bot added the functions Changes to functions implementation label May 14, 2026
@neilconway
Copy link
Copy Markdown
Contributor Author

run benchmark translate

@adriangbot
Copy link
Copy Markdown

🤖 Criterion benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c4452101287-92-2jsfp 6.12.68+ #1 SMP Wed Apr 1 02:23:28 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing neilc/perf-translate-builder (2dcbd5b) to 18a219c (merge-base) diff
BENCH_NAME=translate
BENCH_COMMAND=cargo bench --features=parquet --bench translate
BENCH_FILTER=
Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot
Copy link
Copy Markdown

🤖 Criterion benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

group                                                         main                                   neilc_perf-translate-builder
-----                                                         ----                                   ----------------------------
translate size=1024/array_from_to [str_len=1024]              3.16      2.4±0.00ms        ? ?/sec    1.00    750.7±1.19µs        ? ?/sec
translate size=1024/array_from_to [str_len=128]               3.30    332.5±1.17µs        ? ?/sec    1.00    100.8±0.81µs        ? ?/sec
translate size=1024/array_from_to [str_len=32]                3.22    114.3±0.29µs        ? ?/sec    1.00     35.5±0.43µs        ? ?/sec
translate size=1024/array_from_to [str_len=8]                 2.39     60.1±0.08µs        ? ?/sec    1.00     25.2±0.41µs        ? ?/sec
translate size=1024/array_from_to_non_ascii [str_len=1024]                                           1.00      7.4±0.03ms        ? ?/sec
translate size=1024/array_from_to_non_ascii [str_len=128]                                            1.00    962.6±0.48µs        ? ?/sec
translate size=1024/array_from_to_non_ascii [str_len=32]                                             1.00    275.9±0.13µs        ? ?/sec
translate size=1024/array_from_to_non_ascii [str_len=8]                                              1.00    104.7±0.03µs        ? ?/sec
translate size=1024/scalar_from_to [str_len=1024]             1.53    740.5±0.33µs        ? ?/sec    1.00    482.9±0.12µs        ? ?/sec
translate size=1024/scalar_from_to [str_len=128]              1.54     98.6±0.03µs        ? ?/sec    1.00     64.2±0.01µs        ? ?/sec
translate size=1024/scalar_from_to [str_len=32]               1.52     30.9±0.04µs        ? ?/sec    1.00     20.3±0.01µs        ? ?/sec
translate size=1024/scalar_from_to [str_len=8]                1.61     14.0±0.02µs        ? ?/sec    1.00      8.7±0.01µs        ? ?/sec
translate size=4096/array_from_to [str_len=1024]              3.12      9.5±0.03ms        ? ?/sec    1.00      3.1±0.01ms        ? ?/sec
translate size=4096/array_from_to [str_len=128]               2.86   1340.6±2.82µs        ? ?/sec    1.00    468.8±2.39µs        ? ?/sec
translate size=4096/array_from_to [str_len=32]                2.70    465.9±1.18µs        ? ?/sec    1.00    172.8±1.79µs        ? ?/sec
translate size=4096/array_from_to [str_len=8]                 2.44    239.7±0.39µs        ? ?/sec    1.00     98.1±1.73µs        ? ?/sec
translate size=4096/array_from_to_non_ascii [str_len=1024]                                           1.00     29.3±0.06ms        ? ?/sec
translate size=4096/array_from_to_non_ascii [str_len=128]                                            1.00      3.9±0.00ms        ? ?/sec
translate size=4096/array_from_to_non_ascii [str_len=32]                                             1.00   1141.2±0.60µs        ? ?/sec
translate size=4096/array_from_to_non_ascii [str_len=8]                                              1.00    459.5±0.13µs        ? ?/sec
translate size=4096/scalar_from_to [str_len=1024]             1.56      3.0±0.02ms        ? ?/sec    1.00   1931.0±2.66µs        ? ?/sec
translate size=4096/scalar_from_to [str_len=128]              1.55    389.7±0.17µs        ? ?/sec    1.00    252.1±0.14µs        ? ?/sec
translate size=4096/scalar_from_to [str_len=32]               1.54    118.7±0.21µs        ? ?/sec    1.00     77.1±0.01µs        ? ?/sec
translate size=4096/scalar_from_to [str_len=8]                1.71     52.8±0.04µs        ? ?/sec    1.00     30.9±0.01µs        ? ?/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 230.1s
Peak memory 4.2 GiB
Avg memory 4.2 GiB
CPU user 257.2s
CPU sys 0.9s
Peak spill 0 B

branch

Metric Value
Wall time 345.1s
Peak memory 4.3 GiB
Avg memory 4.2 GiB
CPU user 385.2s
CPU sys 0.4s
Peak spill 0 B

File an issue against this benchmark runner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize translate using append_with

2 participants