Commit 4f36125
committed
Add ASCII fast path optimization to replace function
Add a fast path for replacing single ASCII characters with another single
ASCII character, matching Rust's str::replace() optimization. This enables
vectorization and avoids UTF-8 boundary checking overhead.
Changes:
- Added ASCII character detection in replace_into_string()
- When both 'from' and 'to' are single ASCII bytes, use direct byte mapping
- Updated benchmark to include single ASCII character replacement tests
Optimization:
- Fast path operates directly on bytes using simple map operation
- Compiler can vectorize the byte-wise replacement
- Avoids overhead of match_indices() pattern matching for this common case
Benchmark Results (Single ASCII Character Replacement) against previous commit:
- size=1024, str_len=32: 29.5 µs → 21.4 µs (27% faster)
- size=1024, str_len=128: 73.9 µs → 23.4 µs (68% faster)
- size=4096, str_len=32: 121.8 µs → 85.6 µs (30% faster)
- size=4096, str_len=128: 316.9 µs → 83.8 µs (74% faster)
The optimization shows exceptional 27-74% improvements, with the benefit
scaling dramatically with string length. For 128-character strings, we
achieve over 3x speedup by enabling vectorization and eliminating
pattern matching overhead.
This addresses reviewer feedback about capturing Rust's str::replace()
optimization tricks for single ASCII character replacements.1 parent c10d410 commit 4f36125
File tree
2 files changed
+55
-11
lines changed- datafusion/functions
- benches
- src/string
2 files changed
+55
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
42 | | - | |
43 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
44 | 49 | | |
45 | 50 | | |
46 | 51 | | |
| |||
49 | 54 | | |
50 | 55 | | |
51 | 56 | | |
52 | | - | |
53 | | - | |
| 57 | + | |
| 58 | + | |
54 | 59 | | |
55 | 60 | | |
56 | 61 | | |
| |||
87 | 92 | | |
88 | 93 | | |
89 | 94 | | |
90 | | - | |
| 95 | + | |
91 | 96 | | |
92 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
93 | 110 | | |
94 | 111 | | |
95 | 112 | | |
| |||
100 | 117 | | |
101 | 118 | | |
102 | 119 | | |
103 | | - | |
| 120 | + | |
104 | 121 | | |
105 | 122 | | |
106 | 123 | | |
| |||
111 | 128 | | |
112 | 129 | | |
113 | 130 | | |
114 | | - | |
| 131 | + | |
115 | 132 | | |
116 | 133 | | |
117 | 134 | | |
| |||
124 | 141 | | |
125 | 142 | | |
126 | 143 | | |
127 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
128 | 156 | | |
129 | 157 | | |
130 | 158 | | |
| |||
135 | 163 | | |
136 | 164 | | |
137 | 165 | | |
138 | | - | |
| 166 | + | |
139 | 167 | | |
140 | 168 | | |
141 | 169 | | |
| |||
146 | 174 | | |
147 | 175 | | |
148 | 176 | | |
149 | | - | |
| 177 | + | |
150 | 178 | | |
151 | 179 | | |
152 | 180 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
231 | 247 | | |
232 | 248 | | |
233 | 249 | | |
| |||
0 commit comments