Commit c560bee
authored
perf: Optimize repeat function for scalar and array fast (#19976)
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->
- Part of apache/datafusion-comet#2986.
## Rationale for this change
The `repeat` function currently converts scalar inputs to arrays before
processing via `make_scalar_function`. Adding a scalar fast path avoids
this overhead and improves performance for constant folding and scalar
expression evaluation.
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
## What changes are included in this PR?
1. Refactored `invoke_with_args` to handle scalar inputs directly
without array conversion
2. Added scalar fast path for `Utf8`, `LargeUtf8`, and `Utf8View` scalar
inputs
3. Added array fast path that skips per-element null checks when
`null_count() == 0`
| Type | Before | After | Speedup |
|------|--------|-------|---------|
| **repeat/scalar_utf8** | 519 ns | 91 ns | **5.7x** |
| **repeat/scalar_utf8view** | 437 ns | 91 ns | **4.8x** |
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
## Are these changes tested?
Yes
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
## Are there any user-facing changes?
No
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->1 parent 58fb6e1 commit c560bee
2 files changed
Lines changed: 167 additions & 36 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
83 | 122 | | |
84 | 123 | | |
85 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
102 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
103 | 160 | | |
104 | 161 | | |
105 | 162 | | |
106 | 163 | | |
107 | 164 | | |
108 | 165 | | |
109 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
110 | 184 | | |
111 | 185 | | |
112 | | - | |
113 | | - | |
114 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
115 | 189 | | |
116 | | - | |
| 190 | + | |
117 | 191 | | |
118 | 192 | | |
119 | 193 | | |
120 | 194 | | |
121 | 195 | | |
122 | 196 | | |
123 | 197 | | |
124 | | - | |
| 198 | + | |
125 | 199 | | |
126 | | - | |
| 200 | + | |
127 | 201 | | |
128 | 202 | | |
129 | 203 | | |
130 | 204 | | |
131 | 205 | | |
132 | | - | |
| 206 | + | |
133 | 207 | | |
134 | | - | |
| 208 | + | |
135 | 209 | | |
136 | 210 | | |
137 | 211 | | |
| |||
150 | 224 | | |
151 | 225 | | |
152 | 226 | | |
153 | | - | |
| 227 | + | |
154 | 228 | | |
155 | 229 | | |
156 | 230 | | |
| |||
181 | 255 | | |
182 | 256 | | |
183 | 257 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
188 | 293 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
205 | 297 | | |
206 | 298 | | |
207 | 299 | | |
208 | 300 | | |
209 | 301 | | |
210 | 302 | | |
211 | | - | |
212 | | - | |
| 303 | + | |
| 304 | + | |
213 | 305 | | |
214 | | - | |
| 306 | + | |
215 | 307 | | |
216 | 308 | | |
217 | 309 | | |
| |||
0 commit comments