You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/07/15 16:57:55 UTC
(datafusion-comet) branch asf-site updated: Publish built docs triggered by 02170ecffa557be98d05f3bf4b09e27ac24e6667
This is an automated email from the ASF dual-hosted git repository.
github-actions[bot] pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/datafusion-comet.git
The following commit(s) were added to refs/heads/asf-site by this push:
new ff51793eca Publish built docs triggered by 02170ecffa557be98d05f3bf4b09e27ac24e6667
ff51793eca is described below
commit ff51793ecaad29f64a40ca75b8b0168199000391
Author: github-actions[bot] <gi...@users.noreply.github.com>
AuthorDate: Wed Jul 15 16:57:50 2026 +0000
Publish built docs triggered by 02170ecffa557be98d05f3bf4b09e27ac24e6667
---
.../expression-audits/collection_funcs.md.txt | 1 +
.../expression-audits/conversion_funcs.md.txt | 1 +
.../expression-audits/index.md.txt | 7 +-
.../expression-audits/json_funcs.md.txt | 1 +
.../expression-audits/math_funcs.md.txt | 1 +
.../expression-audits/url_funcs.md.txt | 4 +
_sources/contributor-guide/index.md.txt | 1 +
.../optimizing_expressions.md.txt | 205 +++++++++
contributor-guide/adding_a_new_expression.html | 1 +
contributor-guide/adding_a_new_operator.html | 1 +
contributor-guide/adding_a_new_spark_version.html | 1 +
contributor-guide/benchmark-results/tpc-ds.html | 1 +
contributor-guide/benchmark-results/tpc-h.html | 1 +
contributor-guide/benchmarking.html | 1 +
contributor-guide/benchmarking_aws_ec2.html | 1 +
contributor-guide/benchmarking_macos.html | 1 +
contributor-guide/benchmarking_spark_sql_perf.html | 7 +-
contributor-guide/bug_triage.html | 1 +
contributor-guide/contributing.html | 1 +
contributor-guide/debugging.html | 1 +
contributor-guide/development.html | 1 +
contributor-guide/expression-audits/agg_funcs.html | 1 +
.../expression-audits/array_funcs.html | 1 +
.../expression-audits/bitwise_funcs.html | 1 +
.../expression-audits/collection_funcs.html | 2 +
.../expression-audits/conditional_funcs.html | 1 +
.../expression-audits/conversion_funcs.html | 2 +
.../expression-audits/datetime_funcs.html | 1 +
.../expression-audits/generator_funcs.html | 1 +
.../expression-audits/hash_funcs.html | 1 +
contributor-guide/expression-audits/index.html | 8 +-
.../expression-audits/json_funcs.html | 2 +
contributor-guide/expression-audits/map_funcs.html | 1 +
.../expression-audits/math_funcs.html | 2 +
.../expression-audits/misc_funcs.html | 1 +
.../expression-audits/predicate_funcs.html | 1 +
.../expression-audits/string_funcs.html | 1 +
.../expression-audits/struct_funcs.html | 1 +
contributor-guide/expression-audits/url_funcs.html | 8 +
.../expression-audits/window_funcs.html | 1 +
contributor-guide/ffi.html | 1 +
contributor-guide/iceberg-spark-tests.html | 1 +
contributor-guide/index.html | 1 +
contributor-guide/jvm_shuffle.html | 1 +
contributor-guide/native_shuffle.html | 1 +
...vm_shuffle.html => optimizing_expressions.html} | 466 +++++++++------------
contributor-guide/plugin_overview.html | 1 +
contributor-guide/profiling.html | 7 +-
contributor-guide/release_process.html | 1 +
contributor-guide/roadmap.html | 1 +
.../s3-credential-provider-design.html | 1 +
contributor-guide/spark-sql-tests.html | 1 +
contributor-guide/spark_configs_support.html | 1 +
contributor-guide/sql-file-tests.html | 1 +
contributor-guide/sql_error_propagation.html | 1 +
contributor-guide/tracing.html | 1 +
genindex.html | 1 +
objects.inv | Bin 3748 -> 3778 bytes
search.html | 1 +
searchindex.js | 2 +-
.../expressions/_category_template/aggregate.html | 1 +
.../expressions/_category_template/array.html | 1 +
.../expressions/_category_template/cast.html | 1 +
.../expressions/_category_template/datetime.html | 1 +
.../expressions/_category_template/map.html | 1 +
.../expressions/_category_template/math.html | 1 +
.../expressions/_category_template/misc.html | 1 +
.../expressions/_category_template/string.html | 1 +
.../expressions/_category_template/struct.html | 1 +
.../expressions/_category_template/url.html | 1 +
70 files changed, 509 insertions(+), 269 deletions(-)
diff --git a/_sources/contributor-guide/expression-audits/collection_funcs.md.txt b/_sources/contributor-guide/expression-audits/collection_funcs.md.txt
index a2dd7bd511..94faddcf4a 100644
--- a/_sources/contributor-guide/expression-audits/collection_funcs.md.txt
+++ b/_sources/contributor-guide/expression-audits/collection_funcs.md.txt
@@ -48,5 +48,6 @@
- Spark 4.0.1 (audited 2026-05-27): byte-for-byte identical to 3.5.8.
- Spark 4.1.1 (audited 2026-05-27): byte-for-byte identical to 3.5.8.
- Known limitation: `Size` over `MapType` falls back to Spark (https://github.com/apache/datafusion-comet/issues/4472).
+- Performance (tuned 2026-07-10, PR #4877): compute list row sizes from the offset buffer instead of allocating a sliced `ArrayRef` per row via `list_array.value(i)`, removing one heap allocation per row. ~94% faster. Benchmark: `benches/array_size.rs`.
[Spark Expression Support]: ../../user-guide/latest/expressions.md
diff --git a/_sources/contributor-guide/expression-audits/conversion_funcs.md.txt b/_sources/contributor-guide/expression-audits/conversion_funcs.md.txt
index 45b6a8f03b..b725e3b00a 100644
--- a/_sources/contributor-guide/expression-audits/conversion_funcs.md.txt
+++ b/_sources/contributor-guide/expression-audits/conversion_funcs.md.txt
@@ -35,5 +35,6 @@
- `spark.sql.legacy.castComplexTypesToString.enabled=true` is not honoured by Comet (https://github.com/apache/datafusion-comet/issues/4492).
- `CAST(<float|double> AS DECIMAL)` rounding may differ from Spark (`Incompatible`, gated by `spark.comet.expression.Cast.allowIncompatible`, tracked at https://github.com/apache/datafusion-comet/issues/1371).
- Spark registers the type-name conversion functions (`bigint`, `binary`, `boolean`, `date`, `decimal`, `double`, `float`, `int`, `smallint`, `string`, `timestamp`, `tinyint`) as cast aliases. Each lowers to the same `Cast` node, so Comet handles it via the `cast` implementation with the same compatibility profile.
+- Performance (tuned 2026-07-14, PR #4920): narrowing integer casts (`spark_cast_int_to_int`) map the values buffer in a single pass with Arrow `unary`/`try_unary` and carry the null buffer over untouched, replacing an element-by-element `Option`/`Result` iterator-collect. Up to 100x faster on narrowing casts. Benchmark: `benches/cast_numeric.rs`.
[Spark Expression Support]: ../../user-guide/latest/expressions.md
diff --git a/_sources/contributor-guide/expression-audits/index.md.txt b/_sources/contributor-guide/expression-audits/index.md.txt
index 18b124cba1..5ec596ca51 100644
--- a/_sources/contributor-guide/expression-audits/index.md.txt
+++ b/_sources/contributor-guide/expression-audits/index.md.txt
@@ -21,7 +21,12 @@
This section records per-version audit notes for Spark expressions that have been audited for Comet compatibility. These are findings from auditing the Spark implementation across versions (3.4.3, 3.5.8, 4.0.1), not a statement of support status.
-For the authoritative list of which expressions Comet supports, see the user guide [Spark Expression Support](../../user-guide/latest/expressions.md). To audit an expression, use the `audit-comet-expression` skill, which appends its findings to the relevant category page below.
+Two kinds of audit are recorded per expression:
+
+- **Correctness audits** compare the Spark implementation across versions and note divergences and test-coverage gaps. Use the `audit-comet-expression` skill, which appends its findings to the relevant category page below.
+- **Performance audits** record when a native expression has been performance-tuned, so contributors can see at a glance which expressions have already been optimized. Recorded as a dated `Performance (tuned ...)` line under the expression, they name the technique, the measured speedup, the linking PR, and the benchmark file. Use the `optimize-comet-expression` skill (see [Optimizing Scalar Expressions](../optimizing_expressions.md)), which appends this line after a change is benchmarked [...]
+
+For the authoritative list of which expressions Comet supports, see the user guide [Spark Expression Support](../../user-guide/latest/expressions.md).
```{toctree}
:maxdepth: 1
diff --git a/_sources/contributor-guide/expression-audits/json_funcs.md.txt b/_sources/contributor-guide/expression-audits/json_funcs.md.txt
index 689142e2a3..9518cc6f70 100644
--- a/_sources/contributor-guide/expression-audits/json_funcs.md.txt
+++ b/_sources/contributor-guide/expression-audits/json_funcs.md.txt
@@ -42,5 +42,6 @@
## to_json
- Partial native support; options and map/array inputs fall back.
+- Performance (tuned 2026-07-13, PR #4902): `escape_string` returns `Cow` (zero-alloc borrow when nothing needs escaping) and bulk-copies unescaped byte runs instead of pushing char-by-char per value. 2x faster. Benchmark: `benches/to_json.rs`.
[Spark Expression Support]: ../../user-guide/latest/expressions.md
diff --git a/_sources/contributor-guide/expression-audits/math_funcs.md.txt b/_sources/contributor-guide/expression-audits/math_funcs.md.txt
index 0edb9fac09..f7705d8255 100644
--- a/_sources/contributor-guide/expression-audits/math_funcs.md.txt
+++ b/_sources/contributor-guide/expression-audits/math_funcs.md.txt
@@ -264,6 +264,7 @@
## unhex
- Spark 3.4.3, 3.5.8, 4.0.1, 4.1.1 (audited 2026-05-27): `Unhex(child, failOnError)`. Spark 4.x widens input to `StringTypeWithCollation` and wraps the inner call in try/catch; Comet `CometUnhex` forwards `failOnError` to native `spark_unhex` but does not gate on collation.
+- Performance (tuned 2026-07-11, PR #4876): compile-time 256-entry hex lookup table plus a preallocated `BinaryBuilder`, cutting per-byte branching and repeated buffer reallocations. Up to 31% faster on long strings. Benchmark: `benches/unhex.rs`.
## width_bucket
diff --git a/_sources/contributor-guide/expression-audits/url_funcs.md.txt b/_sources/contributor-guide/expression-audits/url_funcs.md.txt
index c262762ef6..2a61c742c8 100644
--- a/_sources/contributor-guide/expression-audits/url_funcs.md.txt
+++ b/_sources/contributor-guide/expression-audits/url_funcs.md.txt
@@ -21,6 +21,10 @@
> Audit notes for expressions in this category that have been audited. Absence of an entry means the expression has not been audited yet, not that it is unsupported. See the user guide [Spark Expression Support] for current support status.
+## parse_url
+
+- Performance (tuned 2026-07-11, PR #4893): cache the compiled query regex in a thread-local single-slot cache keyed by the query key, eliminating per-row `Regex::new()` recompilation in the QUERY-with-key path (the key is constant across a batch in practice). Up to 50x faster. Benchmark: `benches/parse_url.rs`.
+
## try_url_decode
- 4.0.1, 2026-05-05
diff --git a/_sources/contributor-guide/index.md.txt b/_sources/contributor-guide/index.md.txt
index 5236d03b9d..f293961bda 100644
--- a/_sources/contributor-guide/index.md.txt
+++ b/_sources/contributor-guide/index.md.txt
@@ -79,6 +79,7 @@ Iceberg Spark Tests <iceberg-spark-tests.md>
Debugging Guide <debugging>
Benchmarking Guide <benchmarking>
+Optimizing Scalar Expressions <optimizing_expressions>
Profiling <profiling>
Tracing <tracing>
```
diff --git a/_sources/contributor-guide/optimizing_expressions.md.txt b/_sources/contributor-guide/optimizing_expressions.md.txt
new file mode 100644
index 0000000000..a000f91398
--- /dev/null
+++ b/_sources/contributor-guide/optimizing_expressions.md.txt
@@ -0,0 +1,205 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+# Optimizing Scalar Expressions
+
+This guide describes how to optimize the native scalar expression implementations in the
+`datafusion-comet-spark-expr` crate (`native/spark-expr/`). These are the per-row and per-batch
+kernels that run inside DataFusion for Spark-compatible functions such as casts, string
+functions, JSON encoders, and array functions.
+
+The workflow is deliberate: **measure first, keep the output bit-identical, and prove the win
+with a benchmark that covers the shapes where an optimization is most likely to backfire.** Every
+step below exists because skipping it has produced either a no-op PR or a regression.
+
+## When to optimize
+
+Good candidates share these traits:
+
+- The function is called once per row or once per element, so allocation and branching costs
+ multiply by batch size.
+- The hot path allocates (a `String`, a `Vec`, a sliced `ArrayRef`, a compiled `Regex`) on every
+ row, or dispatches an Arrow compute kernel per element.
+- The function already has correctness tests, so behavior is pinned.
+
+Do not optimize speculatively. If you cannot write a benchmark that shows a meaningful
+improvement, there is nothing to submit.
+
+## The workflow
+
+1. **Read the current implementation** in `native/spark-expr/src/`. Identify the per-row cost:
+ allocation, kernel dispatch, UTF-8 decoding, regex compilation, bitmap reads.
+2. **Write or extend a criterion benchmark** in `native/spark-expr/benches/` (see below). Run it
+ on `main` to capture a baseline before changing any code.
+3. **Apply the optimization**, preserving exact semantics (see [Correctness](#correctness-is-non-negotiable)).
+4. **Run the existing unit tests** for the function. They must pass unchanged. Output must be
+ bit-identical to `main`, including null placement and error behavior.
+5. **Re-run the benchmark** against the baseline. Confirm a meaningful speedup on at least one
+ shape **and no meaningful regression on any shape**.
+6. **Submit** with the criterion output pasted into the PR description.
+
+## Writing a benchmark
+
+Each optimized expression should have a criterion benchmark under `native/spark-expr/benches/`
+registered in `native/spark-expr/Cargo.toml`:
+
+```toml
+[[bench]]
+name = "unhex"
+harness = false
+```
+
+Model new benchmarks on an existing one such as `benches/unhex.rs` or `benches/array_size.rs`.
+A benchmark builds representative Arrow arrays (typically 8192 rows, the default batch size),
+wraps the call in `black_box`, and benches several input **shapes**:
+
+```rust
+fn criterion_benchmark(c: &mut Criterion) {
+ let size = 8192;
+ // ... build arrays for each shape ...
+ let mut bench = |name: &str, arr: &ArrayRef| {
+ let args = vec![ColumnarValue::Array(Arc::clone(arr))];
+ c.bench_function(name, |b| {
+ b.iter(|| black_box(spark_unhex(black_box(&args)).unwrap()))
+ });
+ };
+ bench("spark_unhex: all valid", &all_valid);
+ bench("spark_unhex: with nulls", &with_nulls);
+ bench("spark_unhex: long strings", &long_valid);
+ bench("spark_unhex: invalid inputs", &invalid);
+ bench("spark_unhex: mixed hex column", &mixed);
+}
+```
+
+### Cover the shapes that break optimizations
+
+The most common way a "faster" change is actually a regression is that it wins on the shape you
+looked at and loses on one you did not. Always include:
+
+- **No nulls vs. sparse nulls vs. dense nulls.** Fast paths that assume no nulls, or that batch
+ contiguous non-null runs, can be slower than the base loop when nulls are dense.
+- **Short vs. long values.** Allocation savings shrink and copy costs grow as values get longer.
+- **Valid vs. invalid inputs.** Error and fallback paths have different costs.
+- **ASCII vs. non-ASCII** for string functions with an ASCII fast path.
+
+### Running benchmarks
+
+```sh
+cd native
+# capture the baseline on main
+git checkout main
+cargo bench --bench unhex -- --save-baseline main
+# switch to your branch and compare
+git checkout my-branch
+cargo bench --bench unhex -- --baseline main
+```
+
+Criterion reports the percentage change and confidence interval per shape. A change inside the
+noise threshold is not an improvement.
+
+## Correctness is non-negotiable
+
+The output of the optimized function must be **bit-identical** to `main` for every input:
+same values, same null buffer, same errors. Comet does not ship a differential fuzz harness in
+this repo, so the existing unit tests are your correctness gate. If coverage is thin, add tests
+(or run `audit-comet-expression`) before optimizing.
+
+Recurring correctness traps:
+
+- **Null slots must not raise errors.** In ANSI/overflow paths, only apply the fallible
+ conversion to non-null slots. Arrow's `try_unary` does this for you: a garbage value sitting
+ under a null cannot raise a spurious overflow. Hand-rolled loops that read the value before
+ checking the null bit will report errors Spark does not.
+- **Preserve the exact eval-mode semantics.** For example, Legacy narrowing int casts keep the
+ low-order bits (a wrapping `as` conversion), while ANSI raises on overflow. These are different
+ kernels, not a single path with a flag.
+- **Carry the null buffer through untouched** when the values transform is infallible and
+ one-to-one. `unary`/`try_unary` do this; a rebuild-from-iterator does not, and can drop or
+ shift nulls.
+- **Zero-copy buffer reuse must respect offsets and slicing.** Reusing an input array's buffers
+ is only valid when the layout genuinely matches the output.
+
+## Proven techniques
+
+These are the patterns that have produced real speedups in merged and in-flight Comet PRs. Reach
+for the lightest one that fits.
+
+| Technique | What it replaces | Example |
+| ------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| **Vectorized Arrow kernels** (`unary`, `try_unary`, `binary`) | `iter().map().collect()` over `Option`/`Result` | `spark_cast_int_to_int` (up to 100x): map the values buffer in one pass, carry the null buffer over |
+| **`unary_opt` for null-producing conversions** | A builder loop that appends null on overflow, or `unary` + sentinel + `null_if_overflow` (two passes) | int/float-to-decimal casts (28-50%): map overflow to null in one vectorized pass; for the ANSI throw-on-overflow variant, gate a rare element-wise rescan on an O(1) null-count check |
+| **Zero-copy borrow with `Cow`** | Allocating a new `String`/`Vec` per row when most rows are unchanged | `to_json` `escape_string` (2x): borrow when nothing needs escaping, bulk-copy unescaped byte runs |
+| **Zero-copy buffer reuse** | Copying every value into a fresh builder | `cast_binary_to_string` default path (up to 7000x): reuse the binary array's buffers instead of copying |
+| **Preallocate builders to known size** | Repeated buffer growth/reallocation | `spark_unhex`: preallocate `BinaryBuilder` to the known output length |
+| **Compile-time lookup tables** | Per-element range matches / branching | `spark_unhex`: 256-entry hex table instead of per-digit range match |
+| **Cache compiled regex** (thread-local, keyed by the constant arg) | `Regex::new()` per row | `parse_url` QUERY-with-key (50x): the key is constant across a batch |
+| **Read from the offset buffer directly** | `list_array.value(i)` allocating a sliced `ArrayRef` per row | `spark_size`: compute list lengths from offsets, zero allocation |
+| **Typed scans over flat values buffers + hash probe** | A per-element Arrow `eq`/compute kernel that allocates per call | `spark_arrays_overlap` (up to 18x): scan buffers directly, hash probe for large lists |
+| **ASCII / byte-offset fast path** | `chars().count()` and per-char UTF-8 decoding | `substring` (up to 10x), `spark_lpad` (2x): slice by byte offset when input is ASCII |
+| **`memcpy` from a precomputed buffer** | Char-by-char `push` into a scratch `String` | `spark_lpad`: pad from a precomputed repeating pad buffer, write directly into the builder |
+
+Cross-cutting principles behind the table:
+
+- **Hoist work that is constant across the batch** out of the per-row loop (regex compilation,
+ format setup, capacity that depends only on the whole column).
+- **Avoid per-row heap allocation.** Reuse a scratch buffer, or write directly into the output
+ builder.
+- **Prefer bulk operations** (bulk-copy a run, one `extend` per contiguous run) over per-element
+ operations, but verify the dense-null case does not regress.
+- **Watch capacity hints.** A `rows * rows` capacity hint (instead of `rows`) silently
+ over-allocates; fix these when you find them.
+
+## The no-regression rule
+
+**Do not submit an optimization if any benchmark shape is meaningfully slower**, even if another
+shape is dramatically faster. A change that is 90% faster with no nulls but 30% slower with dense
+nulls is a trade-off, not a win, and should either be gated behind a runtime check that picks the
+right path per batch or not submitted at all. A Comet optimization PR was closed for exactly this
+reason (a 30% dense-null regression alongside a 90% no-null win).
+
+## Record the performance audit
+
+Once a tuning change is merged, record it in the per-expression
+[Expression Audits](expression-audits/index.md) so contributors can see which expressions have
+already been optimized and avoid re-treading the same ground. Add a dated `Performance (tuned ...)`
+line under the expression's heading on the relevant category page (create the heading if the
+expression has no audit entry yet):
+
+```markdown
+## unhex
+
+- Performance (tuned 2026-07-11, PR #4876): compile-time 256-entry hex lookup table plus
+ preallocated `BinaryBuilder`; up to 31% faster on long strings. Benchmark: `benches/unhex.rs`.
+```
+
+Name the technique, the measured speedup, the PR, and the benchmark file. Keep it to one line
+per tuning pass so the history stays scannable.
+
+## PR conventions
+
+Optimization PRs are small and follow a consistent shape:
+
+- Title: ``perf: optimize `function_name` (Nx faster)`` with the headline speedup.
+- Rationale: "Optimize existing expression."
+- Changes: one or two sentences naming the specific technique and what per-row cost it removes.
+- Testing: "Existing tests." plus the pasted criterion output for every shape.
+- Keep the diff focused on one expression. Do not bundle unrelated changes.
+
+Follow the standard [Pre-PR checklist](development.md): `make format`, build, and
+`cargo clippy --all-targets --workspace -- -D warnings`.
diff --git a/contributor-guide/adding_a_new_expression.html b/contributor-guide/adding_a_new_expression.html
index 2479d56cef..732c9cd2ed 100644
--- a/contributor-guide/adding_a_new_expression.html
+++ b/contributor-guide/adding_a_new_expression.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/adding_a_new_operator.html b/contributor-guide/adding_a_new_operator.html
index 1e535f3be9..e95962c844 100644
--- a/contributor-guide/adding_a_new_operator.html
+++ b/contributor-guide/adding_a_new_operator.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/adding_a_new_spark_version.html b/contributor-guide/adding_a_new_spark_version.html
index 2caf7f273d..66eb856a71 100644
--- a/contributor-guide/adding_a_new_spark_version.html
+++ b/contributor-guide/adding_a_new_spark_version.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/benchmark-results/tpc-ds.html b/contributor-guide/benchmark-results/tpc-ds.html
index e77b68be54..2788e94d39 100644
--- a/contributor-guide/benchmark-results/tpc-ds.html
+++ b/contributor-guide/benchmark-results/tpc-ds.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/benchmark-results/tpc-h.html b/contributor-guide/benchmark-results/tpc-h.html
index b77d960372..a1125e8733 100644
--- a/contributor-guide/benchmark-results/tpc-h.html
+++ b/contributor-guide/benchmark-results/tpc-h.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/benchmarking.html b/contributor-guide/benchmarking.html
index 3e4b6a5a04..66bc7215e5 100644
--- a/contributor-guide/benchmarking.html
+++ b/contributor-guide/benchmarking.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/benchmarking_aws_ec2.html b/contributor-guide/benchmarking_aws_ec2.html
index 00cc23f962..b55df98205 100644
--- a/contributor-guide/benchmarking_aws_ec2.html
+++ b/contributor-guide/benchmarking_aws_ec2.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/benchmarking_macos.html b/contributor-guide/benchmarking_macos.html
index bbe5b6c218..80747d6c5b 100644
--- a/contributor-guide/benchmarking_macos.html
+++ b/contributor-guide/benchmarking_macos.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/benchmarking_spark_sql_perf.html b/contributor-guide/benchmarking_spark_sql_perf.html
index 5888112514..8232df1e27 100644
--- a/contributor-guide/benchmarking_spark_sql_perf.html
+++ b/contributor-guide/benchmarking_spark_sql_perf.html
@@ -68,7 +68,7 @@ under the License.
<script src="../_static/comet-ux.js?v=97577a30"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
- <link rel="next" title="Profiling" href="profiling.html" />
+ <link rel="next" title="Optimizing Scalar Expressions" href="optimizing_expressions.html" />
<link rel="prev" title="Comet Benchmarking in EC2" href="benchmarking_aws_ec2.html" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2 current active"><a class="current reference internal" href="#">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
@@ -831,11 +832,11 @@ flag in the CLI) must point to the directory containing the <code class="docutil
</div>
</a>
<a class="right-next"
- href="profiling.html"
+ href="optimizing_expressions.html"
title="next page">
<div class="prev-next-info">
<p class="prev-next-subtitle">next</p>
- <p class="prev-next-title">Profiling</p>
+ <p class="prev-next-title">Optimizing Scalar Expressions</p>
</div>
<i class="fa-solid fa-angle-right"></i>
</a>
diff --git a/contributor-guide/bug_triage.html b/contributor-guide/bug_triage.html
index 736a599d62..2a3a26cf9e 100644
--- a/contributor-guide/bug_triage.html
+++ b/contributor-guide/bug_triage.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/contributing.html b/contributor-guide/contributing.html
index b89d5095b3..47499b162d 100644
--- a/contributor-guide/contributing.html
+++ b/contributor-guide/contributing.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/debugging.html b/contributor-guide/debugging.html
index 51da458dfb..a52444c943 100644
--- a/contributor-guide/debugging.html
+++ b/contributor-guide/debugging.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/development.html b/contributor-guide/development.html
index 5e3b9d939d..5addbbc499 100644
--- a/contributor-guide/development.html
+++ b/contributor-guide/development.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/expression-audits/agg_funcs.html b/contributor-guide/expression-audits/agg_funcs.html
index 3f53dd7e94..445f2e7072 100644
--- a/contributor-guide/expression-audits/agg_funcs.html
+++ b/contributor-guide/expression-audits/agg_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/expression-audits/array_funcs.html b/contributor-guide/expression-audits/array_funcs.html
index a09854df3a..306c25af3b 100644
--- a/contributor-guide/expression-audits/array_funcs.html
+++ b/contributor-guide/expression-audits/array_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/expression-audits/bitwise_funcs.html b/contributor-guide/expression-audits/bitwise_funcs.html
index cdbf1e3bc1..1eb4fdc286 100644
--- a/contributor-guide/expression-audits/bitwise_funcs.html
+++ b/contributor-guide/expression-audits/bitwise_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/expression-audits/collection_funcs.html b/contributor-guide/expression-audits/collection_funcs.html
index f641a0f217..0bc969ec44 100644
--- a/contributor-guide/expression-audits/collection_funcs.html
+++ b/contributor-guide/expression-audits/collection_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
@@ -584,6 +585,7 @@ under the License.
<li><p>Spark 4.0.1 (audited 2026-05-27): byte-for-byte identical to 3.5.8.</p></li>
<li><p>Spark 4.1.1 (audited 2026-05-27): byte-for-byte identical to 3.5.8.</p></li>
<li><p>Known limitation: <code class="docutils literal notranslate"><span class="pre">Size</span></code> over <code class="docutils literal notranslate"><span class="pre">MapType</span></code> falls back to Spark (https://github.com/apache/datafusion-comet/issues/4472).</p></li>
+<li><p>Performance (tuned 2026-07-10, PR #4877): compute list row sizes from the offset buffer instead of allocating a sliced <code class="docutils literal notranslate"><span class="pre">ArrayRef</span></code> per row via <code class="docutils literal notranslate"><span class="pre">list_array.value(i)</span></code>, removing one heap allocation per row. ~94% faster. Benchmark: <code class="docutils literal notranslate"><span class="pre">benches/array_size.rs</span></code>.</p></li>
</ul>
</section>
</section>
diff --git a/contributor-guide/expression-audits/conditional_funcs.html b/contributor-guide/expression-audits/conditional_funcs.html
index 072ab8c401..731c48fe44 100644
--- a/contributor-guide/expression-audits/conditional_funcs.html
+++ b/contributor-guide/expression-audits/conditional_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/expression-audits/conversion_funcs.html b/contributor-guide/expression-audits/conversion_funcs.html
index fa8a067299..1e9f4478c5 100644
--- a/contributor-guide/expression-audits/conversion_funcs.html
+++ b/contributor-guide/expression-audits/conversion_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
@@ -568,6 +569,7 @@ under the License.
</ul>
</li>
<li><p>Spark registers the type-name conversion functions (<code class="docutils literal notranslate"><span class="pre">bigint</span></code>, <code class="docutils literal notranslate"><span class="pre">binary</span></code>, <code class="docutils literal notranslate"><span class="pre">boolean</span></code>, <code class="docutils literal notranslate"><span class="pre">date</span></code>, <code class="docutils literal notranslate"><span class="pre">decimal</span></code>, <code class="docut [...]
+<li><p>Performance (tuned 2026-07-14, PR #4920): narrowing integer casts (<code class="docutils literal notranslate"><span class="pre">spark_cast_int_to_int</span></code>) map the values buffer in a single pass with Arrow <code class="docutils literal notranslate"><span class="pre">unary</span></code>/<code class="docutils literal notranslate"><span class="pre">try_unary</span></code> and carry the null buffer over untouched, replacing an element-by-element <code class="docutils literal [...]
</ul>
</section>
</section>
diff --git a/contributor-guide/expression-audits/datetime_funcs.html b/contributor-guide/expression-audits/datetime_funcs.html
index 4e0eb142df..b71b40d8ee 100644
--- a/contributor-guide/expression-audits/datetime_funcs.html
+++ b/contributor-guide/expression-audits/datetime_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/expression-audits/generator_funcs.html b/contributor-guide/expression-audits/generator_funcs.html
index 717b96e9f6..9c9eafb9fd 100644
--- a/contributor-guide/expression-audits/generator_funcs.html
+++ b/contributor-guide/expression-audits/generator_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/expression-audits/hash_funcs.html b/contributor-guide/expression-audits/hash_funcs.html
index 2416cb0ea8..d7586f1e64 100644
--- a/contributor-guide/expression-audits/hash_funcs.html
+++ b/contributor-guide/expression-audits/hash_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/expression-audits/index.html b/contributor-guide/expression-audits/index.html
index 69f75db506..a58af136fc 100644
--- a/contributor-guide/expression-audits/index.html
+++ b/contributor-guide/expression-audits/index.html
@@ -424,6 +424,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
@@ -541,7 +542,12 @@ under the License.
<section id="expression-audits">
<h1>Expression Audits<a class="headerlink" href="#expression-audits" title="Link to this heading">#</a></h1>
<p>This section records per-version audit notes for Spark expressions that have been audited for Comet compatibility. These are findings from auditing the Spark implementation across versions (3.4.3, 3.5.8, 4.0.1), not a statement of support status.</p>
-<p>For the authoritative list of which expressions Comet supports, see the user guide <a class="reference internal" href="../../user-guide/latest/expressions.html"><span class="std std-doc">Spark Expression Support</span></a>. To audit an expression, use the <code class="docutils literal notranslate"><span class="pre">audit-comet-expression</span></code> skill, which appends its findings to the relevant category page below.</p>
+<p>Two kinds of audit are recorded per expression:</p>
+<ul class="simple">
+<li><p><strong>Correctness audits</strong> compare the Spark implementation across versions and note divergences and test-coverage gaps. Use the <code class="docutils literal notranslate"><span class="pre">audit-comet-expression</span></code> skill, which appends its findings to the relevant category page below.</p></li>
+<li><p><strong>Performance audits</strong> record when a native expression has been performance-tuned, so contributors can see at a glance which expressions have already been optimized. Recorded as a dated <code class="docutils literal notranslate"><span class="pre">Performance</span> <span class="pre">(tuned</span> <span class="pre">...)</span></code> line under the expression, they name the technique, the measured speedup, the linking PR, and the benchmark file. Use the <code class="do [...]
+</ul>
+<p>For the authoritative list of which expressions Comet supports, see the user guide <a class="reference internal" href="../../user-guide/latest/expressions.html"><span class="std std-doc">Spark Expression Support</span></a>.</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="agg_funcs.html">agg_funcs</a></li>
diff --git a/contributor-guide/expression-audits/json_funcs.html b/contributor-guide/expression-audits/json_funcs.html
index 319ee4817e..d87fde42ae 100644
--- a/contributor-guide/expression-audits/json_funcs.html
+++ b/contributor-guide/expression-audits/json_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
@@ -578,6 +579,7 @@ under the License.
<h2>to_json<a class="headerlink" href="#to-json" title="Link to this heading">#</a></h2>
<ul class="simple">
<li><p>Partial native support; options and map/array inputs fall back.</p></li>
+<li><p>Performance (tuned 2026-07-13, PR #4902): <code class="docutils literal notranslate"><span class="pre">escape_string</span></code> returns <code class="docutils literal notranslate"><span class="pre">Cow</span></code> (zero-alloc borrow when nothing needs escaping) and bulk-copies unescaped byte runs instead of pushing char-by-char per value. 2x faster. Benchmark: <code class="docutils literal notranslate"><span class="pre">benches/to_json.rs</span></code>.</p></li>
</ul>
</section>
</section>
diff --git a/contributor-guide/expression-audits/map_funcs.html b/contributor-guide/expression-audits/map_funcs.html
index d6cb011a7b..3e6c6c5997 100644
--- a/contributor-guide/expression-audits/map_funcs.html
+++ b/contributor-guide/expression-audits/map_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/expression-audits/math_funcs.html b/contributor-guide/expression-audits/math_funcs.html
index 1d988fea4f..d9edf30d59 100644
--- a/contributor-guide/expression-audits/math_funcs.html
+++ b/contributor-guide/expression-audits/math_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
@@ -912,6 +913,7 @@ under the License.
<h2>unhex<a class="headerlink" href="#unhex" title="Link to this heading">#</a></h2>
<ul class="simple">
<li><p>Spark 3.4.3, 3.5.8, 4.0.1, 4.1.1 (audited 2026-05-27): <code class="docutils literal notranslate"><span class="pre">Unhex(child,</span> <span class="pre">failOnError)</span></code>. Spark 4.x widens input to <code class="docutils literal notranslate"><span class="pre">StringTypeWithCollation</span></code> and wraps the inner call in try/catch; Comet <code class="docutils literal notranslate"><span class="pre">CometUnhex</span></code> forwards <code class="docutils literal notransl [...]
+<li><p>Performance (tuned 2026-07-11, PR #4876): compile-time 256-entry hex lookup table plus a preallocated <code class="docutils literal notranslate"><span class="pre">BinaryBuilder</span></code>, cutting per-byte branching and repeated buffer reallocations. Up to 31% faster on long strings. Benchmark: <code class="docutils literal notranslate"><span class="pre">benches/unhex.rs</span></code>.</p></li>
</ul>
</section>
<section id="width-bucket">
diff --git a/contributor-guide/expression-audits/misc_funcs.html b/contributor-guide/expression-audits/misc_funcs.html
index ef037614a0..88fc0dbe6f 100644
--- a/contributor-guide/expression-audits/misc_funcs.html
+++ b/contributor-guide/expression-audits/misc_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/expression-audits/predicate_funcs.html b/contributor-guide/expression-audits/predicate_funcs.html
index d9c6a9d5cf..117aa9fe5b 100644
--- a/contributor-guide/expression-audits/predicate_funcs.html
+++ b/contributor-guide/expression-audits/predicate_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/expression-audits/string_funcs.html b/contributor-guide/expression-audits/string_funcs.html
index 584929f4a9..46129b8261 100644
--- a/contributor-guide/expression-audits/string_funcs.html
+++ b/contributor-guide/expression-audits/string_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/expression-audits/struct_funcs.html b/contributor-guide/expression-audits/struct_funcs.html
index 4bb3f5cacc..f0e66590fb 100644
--- a/contributor-guide/expression-audits/struct_funcs.html
+++ b/contributor-guide/expression-audits/struct_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/expression-audits/url_funcs.html b/contributor-guide/expression-audits/url_funcs.html
index 943cbb030e..da33fa0565 100644
--- a/contributor-guide/expression-audits/url_funcs.html
+++ b/contributor-guide/expression-audits/url_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
@@ -550,6 +551,12 @@ under the License.
<blockquote>
<div><p>Audit notes for expressions in this category that have been audited. Absence of an entry means the expression has not been audited yet, not that it is unsupported. See the user guide <a class="reference internal" href="../../user-guide/latest/expressions.html"><span class="std std-doc">Spark Expression Support</span></a> for current support status.</p>
</div></blockquote>
+<section id="parse-url">
+<h2>parse_url<a class="headerlink" href="#parse-url" title="Link to this heading">#</a></h2>
+<ul class="simple">
+<li><p>Performance (tuned 2026-07-11, PR #4893): cache the compiled query regex in a thread-local single-slot cache keyed by the query key, eliminating per-row <code class="docutils literal notranslate"><span class="pre">Regex::new()</span></code> recompilation in the QUERY-with-key path (the key is constant across a batch in practice). Up to 50x faster. Benchmark: <code class="docutils literal notranslate"><span class="pre">benches/parse_url.rs</span></code>.</p></li>
+</ul>
+</section>
<section id="try-url-decode">
<h2>try_url_decode<a class="headerlink" href="#try-url-decode" title="Link to this heading">#</a></h2>
<ul class="simple">
@@ -621,6 +628,7 @@ under the License.
</div>
<nav class="bd-toc-nav page-toc" aria-labelledby="pst-page-navigation-heading-2">
<ul class="visible nav section-nav flex-column">
+<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#parse-url">parse_url</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#try-url-decode">try_url_decode</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#url-decode">url_decode</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#url-encode">url_encode</a></li>
diff --git a/contributor-guide/expression-audits/window_funcs.html b/contributor-guide/expression-audits/window_funcs.html
index eb13d0d16c..ea6b6ad302 100644
--- a/contributor-guide/expression-audits/window_funcs.html
+++ b/contributor-guide/expression-audits/window_funcs.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="../benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="../optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/ffi.html b/contributor-guide/ffi.html
index 767276bbd2..0a5f5d364d 100644
--- a/contributor-guide/ffi.html
+++ b/contributor-guide/ffi.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/iceberg-spark-tests.html b/contributor-guide/iceberg-spark-tests.html
index c3ab1ef7b8..03d14f67e6 100644
--- a/contributor-guide/iceberg-spark-tests.html
+++ b/contributor-guide/iceberg-spark-tests.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/index.html b/contributor-guide/index.html
index 2e1cd4be14..0a20afbdf0 100644
--- a/contributor-guide/index.html
+++ b/contributor-guide/index.html
@@ -424,6 +424,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/jvm_shuffle.html b/contributor-guide/jvm_shuffle.html
index 369e3b1cc7..8f453fbda7 100644
--- a/contributor-guide/jvm_shuffle.html
+++ b/contributor-guide/jvm_shuffle.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/native_shuffle.html b/contributor-guide/native_shuffle.html
index 0134ca1589..c4007c137d 100644
--- a/contributor-guide/native_shuffle.html
+++ b/contributor-guide/native_shuffle.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/jvm_shuffle.html b/contributor-guide/optimizing_expressions.html
similarity index 53%
copy from contributor-guide/jvm_shuffle.html
copy to contributor-guide/optimizing_expressions.html
index 369e3b1cc7..1b4e4ea2d3 100644
--- a/contributor-guide/jvm_shuffle.html
+++ b/contributor-guide/optimizing_expressions.html
@@ -29,7 +29,7 @@ under the License.
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
- <title>JVM Shuffle — Apache DataFusion Comet documentation</title>
+ <title>Optimizing Scalar Expressions — Apache DataFusion Comet documentation</title>
@@ -63,13 +63,13 @@ under the License.
<script src="../_static/documentation_options.js?v=5929fcd5"></script>
<script src="../_static/doctools.js?v=9a2dae69"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
- <script>DOCUMENTATION_OPTIONS.pagename = 'contributor-guide/jvm_shuffle';</script>
+ <script>DOCUMENTATION_OPTIONS.pagename = 'contributor-guide/optimizing_expressions';</script>
<script async="true" defer="true" src="https://buttons.github.io/buttons.js"></script>
<script src="../_static/comet-ux.js?v=97577a30"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
- <link rel="next" title="Native Shuffle" href="native_shuffle.html" />
- <link rel="prev" title="Arrow FFI Usage in Comet" href="ffi.html" />
+ <link rel="next" title="Profiling" href="profiling.html" />
+ <link rel="prev" title="TPC-DS Benchmarking with spark-sql-perf" href="benchmarking_spark_sql_perf.html" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="docsearch:language" content="en"/>
@@ -396,11 +396,11 @@ under the License.
<li class="toctree-l1"><a class="reference internal" href="development.html">Development Guide</a></li>
</ul>
<p aria-level="2" class="caption" role="heading"><span class="caption-text">Project Architecture</span></p>
-<ul class="current nav bd-sidenav">
+<ul class="nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="plugin_overview.html">Comet Plugin Architecture</a></li>
<li class="toctree-l1"><a class="reference internal" href="ffi.html">Arrow FFI</a></li>
-<li class="toctree-l1 current active"><a class="current reference internal" href="#">JVM Shuffle</a></li>
+<li class="toctree-l1"><a class="reference internal" href="jvm_shuffle.html">JVM Shuffle</a></li>
<li class="toctree-l1"><a class="reference internal" href="native_shuffle.html">Native Shuffle</a></li>
<li class="toctree-l1"><a class="reference internal" href="sql_error_propagation.html">ANSI Error Propagation</a></li>
<li class="toctree-l1"><a class="reference internal" href="s3-credential-provider-design.html">S3 Credential Provider Design</a></li>
@@ -418,7 +418,7 @@ under the License.
<li class="toctree-l1"><a class="reference internal" href="iceberg-spark-tests.html">Iceberg Spark Tests</a></li>
</ul>
<p aria-level="2" class="caption" role="heading"><span class="caption-text">Debugging and Performance</span></p>
-<ul class="nav bd-sidenav">
+<ul class="current nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="debugging.html">Debugging Guide</a></li>
<li class="toctree-l1 has-children"><a class="reference internal" href="benchmarking.html">Benchmarking Guide</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
<li class="toctree-l2"><a class="reference internal" href="benchmark-results/tpc-h.html">Apache DataFusion Comet: Benchmarks Derived From TPC-H</a></li>
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1 current active"><a class="current reference internal" href="#">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
@@ -507,7 +508,7 @@ under the License.
<li class="breadcrumb-item"><a href="index.html" class="nav-link">Comet Contributor Guide</a></li>
- <li class="breadcrumb-item active" aria-current="page"><span class="ellipsis">JVM Shuffle</span></li>
+ <li class="breadcrumb-item active" aria-current="page"><span class="ellipsis">Optimizing Scalar Expressions</span></li>
</ul>
</nav>
</div>
@@ -542,272 +543,228 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
-<section id="jvm-shuffle">
-<h1>JVM Shuffle<a class="headerlink" href="#jvm-shuffle" title="Link to this heading">#</a></h1>
-<p>This document describes Comet’s JVM-based columnar shuffle implementation (<code class="docutils literal notranslate"><span class="pre">CometColumnarShuffle</span></code>), which
-writes shuffle data in Arrow IPC format using JVM code with native encoding. For the fully native
-alternative, see <a class="reference internal" href="native_shuffle.html"><span class="std std-doc">Native Shuffle</span></a>.</p>
-<section id="overview">
-<h2>Overview<a class="headerlink" href="#overview" title="Link to this heading">#</a></h2>
-<p>Comet provides two shuffle implementations:</p>
+<section id="optimizing-scalar-expressions">
+<h1>Optimizing Scalar Expressions<a class="headerlink" href="#optimizing-scalar-expressions" title="Link to this heading">#</a></h1>
+<p>This guide describes how to optimize the native scalar expression implementations in the
+<code class="docutils literal notranslate"><span class="pre">datafusion-comet-spark-expr</span></code> crate (<code class="docutils literal notranslate"><span class="pre">native/spark-expr/</span></code>). These are the per-row and per-batch
+kernels that run inside DataFusion for Spark-compatible functions such as casts, string
+functions, JSON encoders, and array functions.</p>
+<p>The workflow is deliberate: <strong>measure first, keep the output bit-identical, and prove the win
+with a benchmark that covers the shapes where an optimization is most likely to backfire.</strong> Every
+step below exists because skipping it has produced either a no-op PR or a regression.</p>
+<section id="when-to-optimize">
+<h2>When to optimize<a class="headerlink" href="#when-to-optimize" title="Link to this heading">#</a></h2>
+<p>Good candidates share these traits:</p>
<ul class="simple">
-<li><p><strong>CometNativeShuffle</strong> (<code class="docutils literal notranslate"><span class="pre">CometExchange</span></code>): Fully native shuffle using Rust. Takes columnar input directly
-from Comet native operators and performs partitioning in native code.</p></li>
-<li><p><strong>CometColumnarShuffle</strong> (<code class="docutils literal notranslate"><span class="pre">CometColumnarExchange</span></code>): JVM-based shuffle that operates on rows internally,
-buffers <code class="docutils literal notranslate"><span class="pre">UnsafeRow</span></code>s in memory pages, and uses native code (via JNI) to encode them to Arrow IPC format.
-Uses Spark’s partitioner for partition assignment. Can accept either row-based or columnar input
-(columnar input is converted to rows via <code class="docutils literal notranslate"><span class="pre">ColumnarToRowExec</span></code>).</p></li>
+<li><p>The function is called once per row or once per element, so allocation and branching costs
+multiply by batch size.</p></li>
+<li><p>The hot path allocates (a <code class="docutils literal notranslate"><span class="pre">String</span></code>, a <code class="docutils literal notranslate"><span class="pre">Vec</span></code>, a sliced <code class="docutils literal notranslate"><span class="pre">ArrayRef</span></code>, a compiled <code class="docutils literal notranslate"><span class="pre">Regex</span></code>) on every
+row, or dispatches an Arrow compute kernel per element.</p></li>
+<li><p>The function already has correctness tests, so behavior is pinned.</p></li>
</ul>
-<p>The JVM shuffle is selected via <code class="docutils literal notranslate"><span class="pre">CometShuffleDependency.shuffleType</span></code>.</p>
+<p>Do not optimize speculatively. If you cannot write a benchmark that shows a meaningful
+improvement, there is nothing to submit.</p>
</section>
-<section id="when-jvm-shuffle-is-used">
-<h2>When JVM Shuffle is Used<a class="headerlink" href="#when-jvm-shuffle-is-used" title="Link to this heading">#</a></h2>
-<p>JVM shuffle (<code class="docutils literal notranslate"><span class="pre">CometColumnarExchange</span></code>) is used instead of native shuffle (<code class="docutils literal notranslate"><span class="pre">CometExchange</span></code>) in the following cases:</p>
+<section id="the-workflow">
+<h2>The workflow<a class="headerlink" href="#the-workflow" title="Link to this heading">#</a></h2>
<ol class="arabic simple">
-<li><p><strong>Shuffle mode is explicitly set to “jvm”</strong>: When <code class="docutils literal notranslate"><span class="pre">spark.comet.exec.shuffle.mode</span></code> is set to <code class="docutils literal notranslate"><span class="pre">jvm</span></code>.</p></li>
-<li><p><strong>Child plan is not a Comet native operator</strong>: When the child plan is a Spark row-based operator
-(not a <code class="docutils literal notranslate"><span class="pre">CometPlan</span></code>), JVM shuffle is the only option since native shuffle requires columnar input
-from Comet operators.</p></li>
-<li><p><strong>Unsupported partition key types</strong>: For <code class="docutils literal notranslate"><span class="pre">HashPartitioning</span></code> and <code class="docutils literal notranslate"><span class="pre">RangePartitioning</span></code>, native shuffle
-only supports primitive types as partition keys. Complex types (struct, array, map) cannot be used
-as partition keys in native shuffle and will fall back to JVM columnar shuffle. Note that complex types are
-fully supported as data columns in both implementations.</p></li>
+<li><p><strong>Read the current implementation</strong> in <code class="docutils literal notranslate"><span class="pre">native/spark-expr/src/</span></code>. Identify the per-row cost:
+allocation, kernel dispatch, UTF-8 decoding, regex compilation, bitmap reads.</p></li>
+<li><p><strong>Write or extend a criterion benchmark</strong> in <code class="docutils literal notranslate"><span class="pre">native/spark-expr/benches/</span></code> (see below). Run it
+on <code class="docutils literal notranslate"><span class="pre">main</span></code> to capture a baseline before changing any code.</p></li>
+<li><p><strong>Apply the optimization</strong>, preserving exact semantics (see <a class="reference internal" href="#correctness-is-non-negotiable">Correctness</a>).</p></li>
+<li><p><strong>Run the existing unit tests</strong> for the function. They must pass unchanged. Output must be
+bit-identical to <code class="docutils literal notranslate"><span class="pre">main</span></code>, including null placement and error behavior.</p></li>
+<li><p><strong>Re-run the benchmark</strong> against the baseline. Confirm a meaningful speedup on at least one
+shape <strong>and no meaningful regression on any shape</strong>.</p></li>
+<li><p><strong>Submit</strong> with the criterion output pasted into the PR description.</p></li>
</ol>
</section>
-<section id="input-handling">
-<h2>Input Handling<a class="headerlink" href="#input-handling" title="Link to this heading">#</a></h2>
-<section id="spark-row-based-input">
-<h3>Spark Row-Based Input<a class="headerlink" href="#spark-row-based-input" title="Link to this heading">#</a></h3>
-<p>When the child plan is a Spark row-based operator, <code class="docutils literal notranslate"><span class="pre">CometColumnarExchange</span></code> calls <code class="docutils literal notranslate"><span class="pre">child.execute()</span></code> which
-returns an <code class="docutils literal notranslate"><span class="pre">RDD[InternalRow]</span></code>. The rows flow directly to the JVM shuffle writers.</p>
-</section>
-<section id="comet-columnar-input">
-<h3>Comet Columnar Input<a class="headerlink" href="#comet-columnar-input" title="Link to this heading">#</a></h3>
-<p>When the child plan is a Comet native operator (e.g., <code class="docutils literal notranslate"><span class="pre">CometHashAggregate</span></code>) but JVM shuffle is selected
-(due to shuffle mode setting or unsupported partitioning), <code class="docutils literal notranslate"><span class="pre">CometColumnarExchange</span></code> still calls
-<code class="docutils literal notranslate"><span class="pre">child.execute()</span></code>. Comet operators implement <code class="docutils literal notranslate"><span class="pre">doExecute()</span></code> by wrapping themselves with <code class="docutils literal notranslate"><span class="pre">ColumnarToRowExec</span></code>:</p>
-<div class="highlight-scala notranslate"><div class="highlight"><pre><span></span><span class="c1">// In CometExec base class</span>
-<span class="k">override</span><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">doExecute</span><span class="p">():</span><span class="w"> </span><span class="nc">RDD</span><span class="p">[</span><span class="nc">InternalRow</span><span class="p">]</span><span class="w"> </span><span class="o">=</span>
-<span class="w"> </span><span class="nc">ColumnarToRowExec</span><span class="p">(</span><span class="bp">this</span><span class="p">).</span><span class="n">doExecute</span><span class="p">()</span>
+<section id="writing-a-benchmark">
+<h2>Writing a benchmark<a class="headerlink" href="#writing-a-benchmark" title="Link to this heading">#</a></h2>
+<p>Each optimized expression should have a criterion benchmark under <code class="docutils literal notranslate"><span class="pre">native/spark-expr/benches/</span></code>
+registered in <code class="docutils literal notranslate"><span class="pre">native/spark-expr/Cargo.toml</span></code>:</p>
+<div class="highlight-toml notranslate"><div class="highlight"><pre><span></span><span class="k">[[bench]]</span>
+<span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"unhex"</span>
+<span class="n">harness</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span>
</pre></div>
</div>
-<p>This means the data path becomes:</p>
-<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Comet Native (columnar) → ColumnarToRowExec → rows → JVM Shuffle → Arrow IPC → columnar
+<p>Model new benchmarks on an existing one such as <code class="docutils literal notranslate"><span class="pre">benches/unhex.rs</span></code> or <code class="docutils literal notranslate"><span class="pre">benches/array_size.rs</span></code>.
+A benchmark builds representative Arrow arrays (typically 8192 rows, the default batch size),
+wraps the call in <code class="docutils literal notranslate"><span class="pre">black_box</span></code>, and benches several input <strong>shapes</strong>:</p>
+<div class="highlight-rust notranslate"><div class="highlight"><pre><span></span><span class="k">fn</span><span class="w"> </span><span class="nf">criterion_benchmark</span><span class="p">(</span><span class="n">c</span><span class="p">:</span><span class="w"> </span><span class="kp">&</span><span class="nc">mut</span><span class="w"> </span><span class="n">Criterion</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
+<span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">8192</span><span class="p">;</span>
+<span class="w"> </span><span class="c1">// ... build arrays for each shape ...</span>
+<span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">bench</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">|</span><span class="n">name</span><span class="p">:</span><span class="w"> </span><span class="kp">&</span><span class="kt">str</span><span class="p">,</span><span class="w"> </span><span class="n">arr</span><span class="p">:</span><span class [...]
+<span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="n">args</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="fm">vec!</span><span class="p">[</span><span class="n">ColumnarValue</span><span class="p">::</span><span class="n">Array</span><span class="p">(</span><span class="n">Arc</span><span class="p">::</span><span class="n">clone</span><span class="p">(</span><span class="n">arr</span><span class="p">) [...]
+<span class="w"> </span><span class="n">c</span><span class="p">.</span><span class="n">bench_function</span><span class="p">(</span><span class="n">name</span><span class="p">,</span><span class="w"> </span><span class="o">|</span><span class="n">b</span><span class="o">|</span><span class="w"> </span><span class="p">{</span>
+<span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">iter</span><span class="p">(</span><span class="o">||</span><span class="w"> </span><span class="n">black_box</span><span class="p">(</span><span class="n">spark_unhex</span><span class="p">(</span><span class="n">black_box</span><span class="p">(</span><span class="o">&</span><span class="n">args</span><span class="p">)).</span><span class="n">unwrap</span><span class="p">()))</span>
+<span class="w"> </span><span class="p">});</span>
+<span class="w"> </span><span class="p">};</span>
+<span class="w"> </span><span class="n">bench</span><span class="p">(</span><span class="s">"spark_unhex: all valid"</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">all_valid</span><span class="p">);</span>
+<span class="w"> </span><span class="n">bench</span><span class="p">(</span><span class="s">"spark_unhex: with nulls"</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">with_nulls</span><span class="p">);</span>
+<span class="w"> </span><span class="n">bench</span><span class="p">(</span><span class="s">"spark_unhex: long strings"</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">long_valid</span><span class="p">);</span>
+<span class="w"> </span><span class="n">bench</span><span class="p">(</span><span class="s">"spark_unhex: invalid inputs"</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">invalid</span><span class="p">);</span>
+<span class="w"> </span><span class="n">bench</span><span class="p">(</span><span class="s">"spark_unhex: mixed hex column"</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">mixed</span><span class="p">);</span>
+<span class="p">}</span>
</pre></div>
</div>
-<p>This is less efficient than native shuffle which avoids the columnar-to-row conversion:</p>
-<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Comet Native (columnar) → Native Shuffle → Arrow IPC → columnar
-</pre></div>
-</div>
-</section>
-<section id="why-use-spark-s-partitioner">
-<h3>Why Use Spark’s Partitioner?<a class="headerlink" href="#why-use-spark-s-partitioner" title="Link to this heading">#</a></h3>
-<p>JVM shuffle uses row-based input so it can leverage Spark’s existing partitioner infrastructure
-(<code class="docutils literal notranslate"><span class="pre">partitioner.getPartition(key)</span></code>). This allows Comet to support all of Spark’s partitioning schemes
-without reimplementing them in Rust. Native shuffle, by contrast, serializes the partitioning scheme
-to protobuf and implements the partitioning logic in native code.</p>
-</section>
+<section id="cover-the-shapes-that-break-optimizations">
+<h3>Cover the shapes that break optimizations<a class="headerlink" href="#cover-the-shapes-that-break-optimizations" title="Link to this heading">#</a></h3>
+<p>The most common way a “faster” change is actually a regression is that it wins on the shape you
+looked at and loses on one you did not. Always include:</p>
+<ul class="simple">
+<li><p><strong>No nulls vs. sparse nulls vs. dense nulls.</strong> Fast paths that assume no nulls, or that batch
+contiguous non-null runs, can be slower than the base loop when nulls are dense.</p></li>
+<li><p><strong>Short vs. long values.</strong> Allocation savings shrink and copy costs grow as values get longer.</p></li>
+<li><p><strong>Valid vs. invalid inputs.</strong> Error and fallback paths have different costs.</p></li>
+<li><p><strong>ASCII vs. non-ASCII</strong> for string functions with an ASCII fast path.</p></li>
+</ul>
</section>
-<section id="architecture">
-<h2>Architecture<a class="headerlink" href="#architecture" title="Link to this heading">#</a></h2>
-<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>┌─────────────────────────────────────────────────────────────────────────┐
-│ CometShuffleManager │
-│ - Extends Spark's ShuffleManager │
-│ - Routes to appropriate writer/reader based on ShuffleHandle type │
-└─────────────────────────────────────────────────────────────────────────┘
- │
- ┌────────────────────────┼────────────────────────┐
- ▼ ▼ ▼
-┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────────┐
-│ CometBypassMerge- │ │ CometUnsafe- │ │ CometNative- │
-│ SortShuffleWriter │ │ ShuffleWriter │ │ ShuffleWriter │
-│ (hash-based) │ │ (sort-based) │ │ (fully native) │
-└─────────────────────┘ └─────────────────────┘ └─────────────────────┘
- │ │
- ▼ ▼
-┌─────────────────────┐ ┌─────────────────────┐
-│ CometDiskBlock- │ │ CometShuffleExternal│
-│ Writer │ │ Sorter │
-└─────────────────────┘ └─────────────────────┘
- │ │
- └────────────┬───────────┘
- ▼
- ┌─────────────────────┐
- │ SpillWriter │
- │ (native encoding │
- │ via JNI) │
- └─────────────────────┘
+<section id="running-benchmarks">
+<h3>Running benchmarks<a class="headerlink" href="#running-benchmarks" title="Link to this heading">#</a></h3>
+<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="nb">cd</span><span class="w"> </span>native
+<span class="c1"># capture the baseline on main</span>
+git<span class="w"> </span>checkout<span class="w"> </span>main
+cargo<span class="w"> </span>bench<span class="w"> </span>--bench<span class="w"> </span>unhex<span class="w"> </span>--<span class="w"> </span>--save-baseline<span class="w"> </span>main
+<span class="c1"># switch to your branch and compare</span>
+git<span class="w"> </span>checkout<span class="w"> </span>my-branch
+cargo<span class="w"> </span>bench<span class="w"> </span>--bench<span class="w"> </span>unhex<span class="w"> </span>--<span class="w"> </span>--baseline<span class="w"> </span>main
</pre></div>
</div>
+<p>Criterion reports the percentage change and confidence interval per shape. A change inside the
+noise threshold is not an improvement.</p>
</section>
-<section id="key-classes">
-<h2>Key Classes<a class="headerlink" href="#key-classes" title="Link to this heading">#</a></h2>
-<section id="shuffle-manager">
-<h3>Shuffle Manager<a class="headerlink" href="#shuffle-manager" title="Link to this heading">#</a></h3>
-<div class="pst-scrollable-table-container"><table class="table">
-<thead>
-<tr class="row-odd"><th class="head"><p>Class</p></th>
-<th class="head"><p>Location</p></th>
-<th class="head"><p>Description</p></th>
-</tr>
-</thead>
-<tbody>
-<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">CometShuffleManager</span></code></p></td>
-<td><p><code class="docutils literal notranslate"><span class="pre">.../shuffle/CometShuffleManager.scala</span></code></p></td>
-<td><p>Entry point. Extends Spark’s <code class="docutils literal notranslate"><span class="pre">ShuffleManager</span></code>. Selects writer/reader based on handle type. Delegates non-Comet shuffles to <code class="docutils literal notranslate"><span class="pre">SortShuffleManager</span></code>.</p></td>
-</tr>
-<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">CometShuffleDependency</span></code></p></td>
-<td><p><code class="docutils literal notranslate"><span class="pre">.../shuffle/CometShuffleDependency.scala</span></code></p></td>
-<td><p>Extends <code class="docutils literal notranslate"><span class="pre">ShuffleDependency</span></code>. Contains <code class="docutils literal notranslate"><span class="pre">shuffleType</span></code> (<code class="docutils literal notranslate"><span class="pre">CometColumnarShuffle</span></code> or <code class="docutils literal notranslate"><span class="pre">CometNativeShuffle</span></code>) and schema info.</p></td>
-</tr>
-</tbody>
-</table>
-</div>
</section>
-<section id="shuffle-handles">
-<h3>Shuffle Handles<a class="headerlink" href="#shuffle-handles" title="Link to this heading">#</a></h3>
-<div class="pst-scrollable-table-container"><table class="table">
-<thead>
-<tr class="row-odd"><th class="head"><p>Handle</p></th>
-<th class="head"><p>Writer Strategy</p></th>
-</tr>
-</thead>
-<tbody>
-<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">CometBypassMergeSortShuffleHandle</span></code></p></td>
-<td><p>Hash-based: one file per partition, merged at end</p></td>
-</tr>
-<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">CometSerializedShuffleHandle</span></code></p></td>
-<td><p>Sort-based: records sorted by partition ID, single output</p></td>
-</tr>
-<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">CometNativeShuffleHandle</span></code></p></td>
-<td><p>Fully native shuffle</p></td>
-</tr>
-</tbody>
-</table>
-</div>
-<p>Selection logic in <code class="docutils literal notranslate"><span class="pre">CometShuffleManager.shouldBypassMergeSort()</span></code>:</p>
+<section id="correctness-is-non-negotiable">
+<h2>Correctness is non-negotiable<a class="headerlink" href="#correctness-is-non-negotiable" title="Link to this heading">#</a></h2>
+<p>The output of the optimized function must be <strong>bit-identical</strong> to <code class="docutils literal notranslate"><span class="pre">main</span></code> for every input:
+same values, same null buffer, same errors. Comet does not ship a differential fuzz harness in
+this repo, so the existing unit tests are your correctness gate. If coverage is thin, add tests
+(or run <code class="docutils literal notranslate"><span class="pre">audit-comet-expression</span></code>) before optimizing.</p>
+<p>Recurring correctness traps:</p>
<ul class="simple">
-<li><p>Uses bypass if partitions < threshold AND partitions × cores ≤ max threads</p></li>
-<li><p>Otherwise uses sort-based to avoid OOM from many concurrent writers</p></li>
+<li><p><strong>Null slots must not raise errors.</strong> In ANSI/overflow paths, only apply the fallible
+conversion to non-null slots. Arrow’s <code class="docutils literal notranslate"><span class="pre">try_unary</span></code> does this for you: a garbage value sitting
+under a null cannot raise a spurious overflow. Hand-rolled loops that read the value before
+checking the null bit will report errors Spark does not.</p></li>
+<li><p><strong>Preserve the exact eval-mode semantics.</strong> For example, Legacy narrowing int casts keep the
+low-order bits (a wrapping <code class="docutils literal notranslate"><span class="pre">as</span></code> conversion), while ANSI raises on overflow. These are different
+kernels, not a single path with a flag.</p></li>
+<li><p><strong>Carry the null buffer through untouched</strong> when the values transform is infallible and
+one-to-one. <code class="docutils literal notranslate"><span class="pre">unary</span></code>/<code class="docutils literal notranslate"><span class="pre">try_unary</span></code> do this; a rebuild-from-iterator does not, and can drop or
+shift nulls.</p></li>
+<li><p><strong>Zero-copy buffer reuse must respect offsets and slicing.</strong> Reusing an input array’s buffers
+is only valid when the layout genuinely matches the output.</p></li>
</ul>
</section>
-<section id="writers">
-<h3>Writers<a class="headerlink" href="#writers" title="Link to this heading">#</a></h3>
+<section id="proven-techniques">
+<h2>Proven techniques<a class="headerlink" href="#proven-techniques" title="Link to this heading">#</a></h2>
+<p>These are the patterns that have produced real speedups in merged and in-flight Comet PRs. Reach
+for the lightest one that fits.</p>
<div class="pst-scrollable-table-container"><table class="table">
<thead>
-<tr class="row-odd"><th class="head"><p>Class</p></th>
-<th class="head"><p>Location</p></th>
-<th class="head"><p>Description</p></th>
+<tr class="row-odd"><th class="head"><p>Technique</p></th>
+<th class="head"><p>What it replaces</p></th>
+<th class="head"><p>Example</p></th>
</tr>
</thead>
<tbody>
-<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">CometBypassMergeSortShuffleWriter</span></code></p></td>
-<td><p><code class="docutils literal notranslate"><span class="pre">.../shuffle/CometBypassMergeSortShuffleWriter.java</span></code></p></td>
-<td><p>Hash-based writer. Creates one <code class="docutils literal notranslate"><span class="pre">CometDiskBlockWriter</span></code> per partition. Supports async writes.</p></td>
+<tr class="row-even"><td><p><strong>Vectorized Arrow kernels</strong> (<code class="docutils literal notranslate"><span class="pre">unary</span></code>, <code class="docutils literal notranslate"><span class="pre">try_unary</span></code>, <code class="docutils literal notranslate"><span class="pre">binary</span></code>)</p></td>
+<td><p><code class="docutils literal notranslate"><span class="pre">iter().map().collect()</span></code> over <code class="docutils literal notranslate"><span class="pre">Option</span></code>/<code class="docutils literal notranslate"><span class="pre">Result</span></code></p></td>
+<td><p><code class="docutils literal notranslate"><span class="pre">spark_cast_int_to_int</span></code> (up to 100x): map the values buffer in one pass, carry the null buffer over</p></td>
</tr>
-<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">CometUnsafeShuffleWriter</span></code></p></td>
-<td><p><code class="docutils literal notranslate"><span class="pre">.../shuffle/CometUnsafeShuffleWriter.java</span></code></p></td>
-<td><p>Sort-based writer. Uses <code class="docutils literal notranslate"><span class="pre">CometShuffleExternalSorter</span></code> to buffer and sort records, then merges spill files.</p></td>
+<tr class="row-odd"><td><p><strong><code class="docutils literal notranslate"><span class="pre">unary_opt</span></code> for null-producing conversions</strong></p></td>
+<td><p>A builder loop that appends null on overflow, or <code class="docutils literal notranslate"><span class="pre">unary</span></code> + sentinel + <code class="docutils literal notranslate"><span class="pre">null_if_overflow</span></code> (two passes)</p></td>
+<td><p>int/float-to-decimal casts (28-50%): map overflow to null in one vectorized pass; for the ANSI throw-on-overflow variant, gate a rare element-wise rescan on an O(1) null-count check</p></td>
</tr>
-<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">CometDiskBlockWriter</span></code></p></td>
-<td><p><code class="docutils literal notranslate"><span class="pre">.../shuffle/CometDiskBlockWriter.java</span></code></p></td>
-<td><p>Buffers rows in memory pages for a single partition. Spills to disk via native encoding. Used by bypass writer.</p></td>
+<tr class="row-even"><td><p><strong>Zero-copy borrow with <code class="docutils literal notranslate"><span class="pre">Cow</span></code></strong></p></td>
+<td><p>Allocating a new <code class="docutils literal notranslate"><span class="pre">String</span></code>/<code class="docutils literal notranslate"><span class="pre">Vec</span></code> per row when most rows are unchanged</p></td>
+<td><p><code class="docutils literal notranslate"><span class="pre">to_json</span></code> <code class="docutils literal notranslate"><span class="pre">escape_string</span></code> (2x): borrow when nothing needs escaping, bulk-copy unescaped byte runs</p></td>
</tr>
-<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">CometShuffleExternalSorter</span></code></p></td>
-<td><p><code class="docutils literal notranslate"><span class="pre">.../shuffle/sort/CometShuffleExternalSorter.java</span></code></p></td>
-<td><p>Buffers records across all partitions, sorts by partition ID, spills sorted data. Used by unsafe writer.</p></td>
+<tr class="row-odd"><td><p><strong>Zero-copy buffer reuse</strong></p></td>
+<td><p>Copying every value into a fresh builder</p></td>
+<td><p><code class="docutils literal notranslate"><span class="pre">cast_binary_to_string</span></code> default path (up to 7000x): reuse the binary array’s buffers instead of copying</p></td>
</tr>
-<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">SpillWriter</span></code></p></td>
-<td><p><code class="docutils literal notranslate"><span class="pre">.../shuffle/SpillWriter.java</span></code></p></td>
-<td><p>Base class for spill logic. Manages memory pages and calls <code class="docutils literal notranslate"><span class="pre">Native.writeSortedFileNative()</span></code> for Arrow IPC encoding.</p></td>
+<tr class="row-even"><td><p><strong>Preallocate builders to known size</strong></p></td>
+<td><p>Repeated buffer growth/reallocation</p></td>
+<td><p><code class="docutils literal notranslate"><span class="pre">spark_unhex</span></code>: preallocate <code class="docutils literal notranslate"><span class="pre">BinaryBuilder</span></code> to the known output length</p></td>
</tr>
-</tbody>
-</table>
-</div>
-</section>
-<section id="reader">
-<h3>Reader<a class="headerlink" href="#reader" title="Link to this heading">#</a></h3>
-<div class="pst-scrollable-table-container"><table class="table">
-<thead>
-<tr class="row-odd"><th class="head"><p>Class</p></th>
-<th class="head"><p>Location</p></th>
-<th class="head"><p>Description</p></th>
+<tr class="row-odd"><td><p><strong>Compile-time lookup tables</strong></p></td>
+<td><p>Per-element range matches / branching</p></td>
+<td><p><code class="docutils literal notranslate"><span class="pre">spark_unhex</span></code>: 256-entry hex table instead of per-digit range match</p></td>
</tr>
-</thead>
-<tbody>
-<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">CometBlockStoreShuffleReader</span></code></p></td>
-<td><p><code class="docutils literal notranslate"><span class="pre">.../shuffle/CometBlockStoreShuffleReader.scala</span></code></p></td>
-<td><p>Fetches shuffle blocks via <code class="docutils literal notranslate"><span class="pre">ShuffleBlockFetcherIterator</span></code>. Decodes Arrow IPC to <code class="docutils literal notranslate"><span class="pre">ColumnarBatch</span></code>.</p></td>
+<tr class="row-even"><td><p><strong>Cache compiled regex</strong> (thread-local, keyed by the constant arg)</p></td>
+<td><p><code class="docutils literal notranslate"><span class="pre">Regex::new()</span></code> per row</p></td>
+<td><p><code class="docutils literal notranslate"><span class="pre">parse_url</span></code> QUERY-with-key (50x): the key is constant across a batch</p></td>
+</tr>
+<tr class="row-odd"><td><p><strong>Read from the offset buffer directly</strong></p></td>
+<td><p><code class="docutils literal notranslate"><span class="pre">list_array.value(i)</span></code> allocating a sliced <code class="docutils literal notranslate"><span class="pre">ArrayRef</span></code> per row</p></td>
+<td><p><code class="docutils literal notranslate"><span class="pre">spark_size</span></code>: compute list lengths from offsets, zero allocation</p></td>
</tr>
-<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">NativeBatchDecoderIterator</span></code></p></td>
-<td><p><code class="docutils literal notranslate"><span class="pre">.../shuffle/NativeBatchDecoderIterator.scala</span></code></p></td>
-<td><p>Reads compressed Arrow IPC batches from input stream. Calls <code class="docutils literal notranslate"><span class="pre">Native.decodeShuffleBlock()</span></code> via JNI.</p></td>
+<tr class="row-even"><td><p><strong>Typed scans over flat values buffers + hash probe</strong></p></td>
+<td><p>A per-element Arrow <code class="docutils literal notranslate"><span class="pre">eq</span></code>/compute kernel that allocates per call</p></td>
+<td><p><code class="docutils literal notranslate"><span class="pre">spark_arrays_overlap</span></code> (up to 18x): scan buffers directly, hash probe for large lists</p></td>
+</tr>
+<tr class="row-odd"><td><p><strong>ASCII / byte-offset fast path</strong></p></td>
+<td><p><code class="docutils literal notranslate"><span class="pre">chars().count()</span></code> and per-char UTF-8 decoding</p></td>
+<td><p><code class="docutils literal notranslate"><span class="pre">substring</span></code> (up to 10x), <code class="docutils literal notranslate"><span class="pre">spark_lpad</span></code> (2x): slice by byte offset when input is ASCII</p></td>
+</tr>
+<tr class="row-even"><td><p><strong><code class="docutils literal notranslate"><span class="pre">memcpy</span></code> from a precomputed buffer</strong></p></td>
+<td><p>Char-by-char <code class="docutils literal notranslate"><span class="pre">push</span></code> into a scratch <code class="docutils literal notranslate"><span class="pre">String</span></code></p></td>
+<td><p><code class="docutils literal notranslate"><span class="pre">spark_lpad</span></code>: pad from a precomputed repeating pad buffer, write directly into the builder</p></td>
</tr>
</tbody>
</table>
</div>
+<p>Cross-cutting principles behind the table:</p>
+<ul class="simple">
+<li><p><strong>Hoist work that is constant across the batch</strong> out of the per-row loop (regex compilation,
+format setup, capacity that depends only on the whole column).</p></li>
+<li><p><strong>Avoid per-row heap allocation.</strong> Reuse a scratch buffer, or write directly into the output
+builder.</p></li>
+<li><p><strong>Prefer bulk operations</strong> (bulk-copy a run, one <code class="docutils literal notranslate"><span class="pre">extend</span></code> per contiguous run) over per-element
+operations, but verify the dense-null case does not regress.</p></li>
+<li><p><strong>Watch capacity hints.</strong> A <code class="docutils literal notranslate"><span class="pre">rows</span> <span class="pre">*</span> <span class="pre">rows</span></code> capacity hint (instead of <code class="docutils literal notranslate"><span class="pre">rows</span></code>) silently
+over-allocates; fix these when you find them.</p></li>
+</ul>
</section>
+<section id="the-no-regression-rule">
+<h2>The no-regression rule<a class="headerlink" href="#the-no-regression-rule" title="Link to this heading">#</a></h2>
+<p><strong>Do not submit an optimization if any benchmark shape is meaningfully slower</strong>, even if another
+shape is dramatically faster. A change that is 90% faster with no nulls but 30% slower with dense
+nulls is a trade-off, not a win, and should either be gated behind a runtime check that picks the
+right path per batch or not submitted at all. A Comet optimization PR was closed for exactly this
+reason (a 30% dense-null regression alongside a 90% no-null win).</p>
</section>
-<section id="data-flow">
-<h2>Data Flow<a class="headerlink" href="#data-flow" title="Link to this heading">#</a></h2>
-<section id="write-path">
-<h3>Write Path<a class="headerlink" href="#write-path" title="Link to this heading">#</a></h3>
-<ol class="arabic simple">
-<li><p><code class="docutils literal notranslate"><span class="pre">ShuffleWriteProcessor</span></code> calls <code class="docutils literal notranslate"><span class="pre">CometShuffleManager.getWriter()</span></code></p></li>
-<li><p>Writer receives <code class="docutils literal notranslate"><span class="pre">Iterator[Product2[K,</span> <span class="pre">V]]</span></code> where V is <code class="docutils literal notranslate"><span class="pre">UnsafeRow</span></code></p></li>
-<li><p>Rows are serialized and buffered in off-heap memory pages</p></li>
-<li><p>When memory threshold or batch size is reached, <code class="docutils literal notranslate"><span class="pre">SpillWriter.doSpilling()</span></code> is called</p></li>
-<li><p>Native code (<code class="docutils literal notranslate"><span class="pre">Native.writeSortedFileNative()</span></code>) converts rows to Arrow arrays and writes IPC format</p></li>
-<li><p>For bypass writer: partition files are concatenated into final output</p></li>
-<li><p>For sort writer: spill files are merged</p></li>
-</ol>
-</section>
-<section id="read-path">
-<h3>Read Path<a class="headerlink" href="#read-path" title="Link to this heading">#</a></h3>
-<ol class="arabic simple">
-<li><p><code class="docutils literal notranslate"><span class="pre">CometBlockStoreShuffleReader.read()</span></code> creates <code class="docutils literal notranslate"><span class="pre">ShuffleBlockFetcherIterator</span></code></p></li>
-<li><p>For each block, <code class="docutils literal notranslate"><span class="pre">NativeBatchDecoderIterator</span></code> reads the IPC stream</p></li>
-<li><p>Native code (<code class="docutils literal notranslate"><span class="pre">Native.decodeShuffleBlock()</span></code>) decompresses and decodes to Arrow arrays</p></li>
-<li><p>Arrow FFI imports arrays as <code class="docutils literal notranslate"><span class="pre">ColumnarBatch</span></code></p></li>
-</ol>
-</section>
+<section id="record-the-performance-audit">
+<h2>Record the performance audit<a class="headerlink" href="#record-the-performance-audit" title="Link to this heading">#</a></h2>
+<p>Once a tuning change is merged, record it in the per-expression
+<a class="reference internal" href="expression-audits/index.html"><span class="std std-doc">Expression Audits</span></a> so contributors can see which expressions have
+already been optimized and avoid re-treading the same ground. Add a dated <code class="docutils literal notranslate"><span class="pre">Performance</span> <span class="pre">(tuned</span> <span class="pre">...)</span></code>
+line under the expression’s heading on the relevant category page (create the heading if the
+expression has no audit entry yet):</p>
+<div class="highlight-markdown notranslate"><div class="highlight"><pre><span></span><span class="gu">## unhex</span>
+
+<span class="k">-</span><span class="w"> </span>Performance (tuned 2026-07-11, PR <span class="ni">#4876</span>): compile-time 256-entry hex lookup table plus
+ preallocated <span class="sb">`BinaryBuilder`</span>; up to 31% faster on long strings. Benchmark: <span class="sb">`benches/unhex.rs`</span>.
+</pre></div>
+</div>
+<p>Name the technique, the measured speedup, the PR, and the benchmark file. Keep it to one line
+per tuning pass so the history stays scannable.</p>
</section>
-<section id="memory-management">
-<h2>Memory Management<a class="headerlink" href="#memory-management" title="Link to this heading">#</a></h2>
+<section id="pr-conventions">
+<h2>PR conventions<a class="headerlink" href="#pr-conventions" title="Link to this heading">#</a></h2>
+<p>Optimization PRs are small and follow a consistent shape:</p>
<ul class="simple">
-<li><p><code class="docutils literal notranslate"><span class="pre">CometShuffleMemoryAllocator</span></code>: Custom allocator for off-heap memory pages</p></li>
-<li><p>Memory is allocated in pages; when allocation fails, writers spill to disk</p></li>
-<li><p><code class="docutils literal notranslate"><span class="pre">CometDiskBlockWriter</span></code> coordinates spilling across all partition writers (largest first)</p></li>
-<li><p>Async spilling is supported via <code class="docutils literal notranslate"><span class="pre">ShuffleThreadPool</span></code></p></li>
+<li><p>Title: <code class="docutils literal notranslate"><span class="pre">perf:</span> <span class="pre">optimize</span> <span class="pre">`function_name`</span> <span class="pre">(Nx</span> <span class="pre">faster)</span></code> with the headline speedup.</p></li>
+<li><p>Rationale: “Optimize existing expression.”</p></li>
+<li><p>Changes: one or two sentences naming the specific technique and what per-row cost it removes.</p></li>
+<li><p>Testing: “Existing tests.” plus the pasted criterion output for every shape.</p></li>
+<li><p>Keep the diff focused on one expression. Do not bundle unrelated changes.</p></li>
</ul>
-</section>
-<section id="configuration">
-<h2>Configuration<a class="headerlink" href="#configuration" title="Link to this heading">#</a></h2>
-<div class="pst-scrollable-table-container"><table class="table">
-<thead>
-<tr class="row-odd"><th class="head"><p>Config</p></th>
-<th class="head"><p>Description</p></th>
-</tr>
-</thead>
-<tbody>
-<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">spark.comet.columnar.shuffle.async.enabled</span></code></p></td>
-<td><p>Enable async spill writes</p></td>
-</tr>
-<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">spark.comet.columnar.shuffle.async.thread.num</span></code></p></td>
-<td><p>Threads per writer for async</p></td>
-</tr>
-<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">spark.comet.columnar.shuffle.batch.size</span></code></p></td>
-<td><p>Rows per Arrow batch</p></td>
-</tr>
-<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">spark.comet.columnar.shuffle.spill.threshold</span></code></p></td>
-<td><p>Row count threshold for spill</p></td>
-</tr>
-<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">spark.comet.exec.shuffle.compression.codec</span></code></p></td>
-<td><p>Compression codec (zstd, lz4, etc.)</p></td>
-</tr>
-</tbody>
-</table>
-</div>
+<p>Follow the standard <a class="reference internal" href="development.html"><span class="std std-doc">Pre-PR checklist</span></a>: <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">format</span></code>, build, and
+<code class="docutils literal notranslate"><span class="pre">cargo</span> <span class="pre">clippy</span> <span class="pre">--all-targets</span> <span class="pre">--workspace</span> <span class="pre">--</span> <span class="pre">-D</span> <span class="pre">warnings</span></code>.</p>
</section>
</section>
@@ -822,20 +779,20 @@ to protobuf and implements the partitioning logic in native code.</p>
<div class="prev-next-area">
<a class="left-prev"
- href="ffi.html"
+ href="benchmarking_spark_sql_perf.html"
title="previous page">
<i class="fa-solid fa-angle-left"></i>
<div class="prev-next-info">
<p class="prev-next-subtitle">previous</p>
- <p class="prev-next-title">Arrow FFI Usage in Comet</p>
+ <p class="prev-next-title">TPC-DS Benchmarking with spark-sql-perf</p>
</div>
</a>
<a class="right-next"
- href="native_shuffle.html"
+ href="profiling.html"
title="next page">
<div class="prev-next-info">
<p class="prev-next-subtitle">next</p>
- <p class="prev-next-title">Native Shuffle</p>
+ <p class="prev-next-title">Profiling</p>
</div>
<i class="fa-solid fa-angle-right"></i>
</a>
@@ -858,29 +815,18 @@ to protobuf and implements the partitioning logic in native code.</p>
</div>
<nav class="bd-toc-nav page-toc" aria-labelledby="pst-page-navigation-heading-2">
<ul class="visible nav section-nav flex-column">
-<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#overview">Overview</a></li>
-<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#when-jvm-shuffle-is-used">When JVM Shuffle is Used</a></li>
-<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#input-handling">Input Handling</a><ul class="nav section-nav flex-column">
-<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#spark-row-based-input">Spark Row-Based Input</a></li>
-<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#comet-columnar-input">Comet Columnar Input</a></li>
-<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#why-use-spark-s-partitioner">Why Use Spark’s Partitioner?</a></li>
-</ul>
-</li>
-<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#architecture">Architecture</a></li>
-<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#key-classes">Key Classes</a><ul class="nav section-nav flex-column">
-<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#shuffle-manager">Shuffle Manager</a></li>
-<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#shuffle-handles">Shuffle Handles</a></li>
-<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#writers">Writers</a></li>
-<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#reader">Reader</a></li>
-</ul>
-</li>
-<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#data-flow">Data Flow</a><ul class="nav section-nav flex-column">
-<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#write-path">Write Path</a></li>
-<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#read-path">Read Path</a></li>
+<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#when-to-optimize">When to optimize</a></li>
+<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#the-workflow">The workflow</a></li>
+<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#writing-a-benchmark">Writing a benchmark</a><ul class="nav section-nav flex-column">
+<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#cover-the-shapes-that-break-optimizations">Cover the shapes that break optimizations</a></li>
+<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#running-benchmarks">Running benchmarks</a></li>
</ul>
</li>
-<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#memory-management">Memory Management</a></li>
-<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#configuration">Configuration</a></li>
+<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#correctness-is-non-negotiable">Correctness is non-negotiable</a></li>
+<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#proven-techniques">Proven techniques</a></li>
+<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#the-no-regression-rule">The no-regression rule</a></li>
+<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#record-the-performance-audit">Record the performance audit</a></li>
+<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#pr-conventions">PR conventions</a></li>
</ul>
</nav></div>
diff --git a/contributor-guide/plugin_overview.html b/contributor-guide/plugin_overview.html
index 8a68253c8d..7493850569 100644
--- a/contributor-guide/plugin_overview.html
+++ b/contributor-guide/plugin_overview.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/profiling.html b/contributor-guide/profiling.html
index 8cc617d4f4..4d86473050 100644
--- a/contributor-guide/profiling.html
+++ b/contributor-guide/profiling.html
@@ -69,7 +69,7 @@ under the License.
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="Tracing" href="tracing.html" />
- <link rel="prev" title="TPC-DS Benchmarking with spark-sql-perf" href="benchmarking_spark_sql_perf.html" />
+ <link rel="prev" title="Optimizing Scalar Expressions" href="optimizing_expressions.html" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="docsearch:language" content="en"/>
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1 current active"><a class="current reference internal" href="#">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
@@ -883,12 +884,12 @@ time is split between Spark’s JVM code and Comet’s native execution.</p>
<div class="prev-next-area">
<a class="left-prev"
- href="benchmarking_spark_sql_perf.html"
+ href="optimizing_expressions.html"
title="previous page">
<i class="fa-solid fa-angle-left"></i>
<div class="prev-next-info">
<p class="prev-next-subtitle">previous</p>
- <p class="prev-next-title">TPC-DS Benchmarking with spark-sql-perf</p>
+ <p class="prev-next-title">Optimizing Scalar Expressions</p>
</div>
</a>
<a class="right-next"
diff --git a/contributor-guide/release_process.html b/contributor-guide/release_process.html
index e6ca663427..48269ff53b 100644
--- a/contributor-guide/release_process.html
+++ b/contributor-guide/release_process.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/roadmap.html b/contributor-guide/roadmap.html
index d9c9a683a2..6b5c0631f6 100644
--- a/contributor-guide/roadmap.html
+++ b/contributor-guide/roadmap.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/s3-credential-provider-design.html b/contributor-guide/s3-credential-provider-design.html
index d019ac25e5..4c129fa96a 100644
--- a/contributor-guide/s3-credential-provider-design.html
+++ b/contributor-guide/s3-credential-provider-design.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/spark-sql-tests.html b/contributor-guide/spark-sql-tests.html
index 2ce1f8a449..138cff09bc 100644
--- a/contributor-guide/spark-sql-tests.html
+++ b/contributor-guide/spark-sql-tests.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/spark_configs_support.html b/contributor-guide/spark_configs_support.html
index 562c161270..f453b8960c 100644
--- a/contributor-guide/spark_configs_support.html
+++ b/contributor-guide/spark_configs_support.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/sql-file-tests.html b/contributor-guide/sql-file-tests.html
index d053493f4a..b972f2e700 100644
--- a/contributor-guide/sql-file-tests.html
+++ b/contributor-guide/sql-file-tests.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/sql_error_propagation.html b/contributor-guide/sql_error_propagation.html
index 2d85e1de80..d08b080992 100644
--- a/contributor-guide/sql_error_propagation.html
+++ b/contributor-guide/sql_error_propagation.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="tracing.html">Tracing</a></li>
</ul>
diff --git a/contributor-guide/tracing.html b/contributor-guide/tracing.html
index ae22e40390..f7a2cddac7 100644
--- a/contributor-guide/tracing.html
+++ b/contributor-guide/tracing.html
@@ -428,6 +428,7 @@ under the License.
<li class="toctree-l2"><a class="reference internal" href="benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l1"><a class="reference internal" href="optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiling.html">Profiling</a></li>
<li class="toctree-l1 current active"><a class="current reference internal" href="#">Tracing</a></li>
</ul>
diff --git a/genindex.html b/genindex.html
index 9c69156c86..0d287d7401 100644
--- a/genindex.html
+++ b/genindex.html
@@ -542,6 +542,7 @@ under the License.
<li class="toctree-l3"><a class="reference internal" href="contributor-guide/benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l2"><a class="reference internal" href="contributor-guide/optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="contributor-guide/profiling.html">Profiling</a></li>
<li class="toctree-l2"><a class="reference internal" href="contributor-guide/tracing.html">Tracing</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="contributor-guide/expression-audits/index.html">Expression Audits</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
diff --git a/objects.inv b/objects.inv
index ee11da2271..df38923e8f 100644
Binary files a/objects.inv and b/objects.inv differ
diff --git a/search.html b/search.html
index af72719aae..cfb5c8fc74 100644
--- a/search.html
+++ b/search.html
@@ -544,6 +544,7 @@ under the License.
<li class="toctree-l3"><a class="reference internal" href="contributor-guide/benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l2"><a class="reference internal" href="contributor-guide/optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="contributor-guide/profiling.html">Profiling</a></li>
<li class="toctree-l2"><a class="reference internal" href="contributor-guide/tracing.html">Tracing</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="contributor-guide/expression-audits/index.html">Expression Audits</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
diff --git a/searchindex.js b/searchindex.js
index 2ba442ef5c..f6f9baf8c6 100644
--- a/searchindex.js
+++ b/searchindex.js
@@ -1 +1 @@
-Search.setIndex({"alltitles": {"!": [[51, "id1"]], "%": [[49, "id1"]], "&": [[39, "id1"]], "*": [[49, "id2"]], "+": [[49, "id3"]], "-": [[49, "id4"]], "/": [[49, "id5"]], "1. Format Your Code": [[36, "format-your-code"]], "1. Install Comet": [[57, "install-comet"], [66, "install-comet"]], "1. Native Operators (nativeExecs map)": [[25, "native-operators-nativeexecs-map"]], "2. Build and Verify": [[36, "build-and-verify"]], "2. Clone Iceberg and Apply Diff": [[57, "clone-iceberg-and-apply- [...]
\ No newline at end of file
+Search.setIndex({"alltitles": {"!": [[51, "id1"]], "%": [[49, "id1"]], "&": [[39, "id1"]], "*": [[49, "id2"]], "+": [[49, "id3"]], "-": [[49, "id4"]], "/": [[49, "id5"]], "1. Format Your Code": [[36, "format-your-code"]], "1. Install Comet": [[57, "install-comet"], [67, "install-comet"]], "1. Native Operators (nativeExecs map)": [[25, "native-operators-nativeexecs-map"]], "2. Build and Verify": [[36, "build-and-verify"]], "2. Clone Iceberg and Apply Diff": [[57, "clone-iceberg-and-apply- [...]
\ No newline at end of file
diff --git a/user-guide/0.17/compatibility/expressions/_category_template/aggregate.html b/user-guide/0.17/compatibility/expressions/_category_template/aggregate.html
index 1ad9a0b682..a69ecfdd5e 100644
--- a/user-guide/0.17/compatibility/expressions/_category_template/aggregate.html
+++ b/user-guide/0.17/compatibility/expressions/_category_template/aggregate.html
@@ -543,6 +543,7 @@ under the License.
<li class="toctree-l3"><a class="reference internal" href="../../../../../contributor-guide/benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/profiling.html">Profiling</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/tracing.html">Tracing</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../../../../contributor-guide/expression-audits/index.html">Expression Audits</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
diff --git a/user-guide/0.17/compatibility/expressions/_category_template/array.html b/user-guide/0.17/compatibility/expressions/_category_template/array.html
index a2c242bb9d..dbdf305be4 100644
--- a/user-guide/0.17/compatibility/expressions/_category_template/array.html
+++ b/user-guide/0.17/compatibility/expressions/_category_template/array.html
@@ -543,6 +543,7 @@ under the License.
<li class="toctree-l3"><a class="reference internal" href="../../../../../contributor-guide/benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/profiling.html">Profiling</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/tracing.html">Tracing</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../../../../contributor-guide/expression-audits/index.html">Expression Audits</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
diff --git a/user-guide/0.17/compatibility/expressions/_category_template/cast.html b/user-guide/0.17/compatibility/expressions/_category_template/cast.html
index a0c1c5b656..1350ea06cb 100644
--- a/user-guide/0.17/compatibility/expressions/_category_template/cast.html
+++ b/user-guide/0.17/compatibility/expressions/_category_template/cast.html
@@ -547,6 +547,7 @@ under the License.
<li class="toctree-l3"><a class="reference internal" href="../../../../../contributor-guide/benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/profiling.html">Profiling</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/tracing.html">Tracing</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../../../../contributor-guide/expression-audits/index.html">Expression Audits</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
diff --git a/user-guide/0.17/compatibility/expressions/_category_template/datetime.html b/user-guide/0.17/compatibility/expressions/_category_template/datetime.html
index 3f4f0009c6..99df305bf6 100644
--- a/user-guide/0.17/compatibility/expressions/_category_template/datetime.html
+++ b/user-guide/0.17/compatibility/expressions/_category_template/datetime.html
@@ -547,6 +547,7 @@ under the License.
<li class="toctree-l3"><a class="reference internal" href="../../../../../contributor-guide/benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/profiling.html">Profiling</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/tracing.html">Tracing</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../../../../contributor-guide/expression-audits/index.html">Expression Audits</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
diff --git a/user-guide/0.17/compatibility/expressions/_category_template/map.html b/user-guide/0.17/compatibility/expressions/_category_template/map.html
index 45123903b0..31a021df95 100644
--- a/user-guide/0.17/compatibility/expressions/_category_template/map.html
+++ b/user-guide/0.17/compatibility/expressions/_category_template/map.html
@@ -547,6 +547,7 @@ under the License.
<li class="toctree-l3"><a class="reference internal" href="../../../../../contributor-guide/benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/profiling.html">Profiling</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/tracing.html">Tracing</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../../../../contributor-guide/expression-audits/index.html">Expression Audits</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
diff --git a/user-guide/0.17/compatibility/expressions/_category_template/math.html b/user-guide/0.17/compatibility/expressions/_category_template/math.html
index 7ca599b36c..2ddc9579fa 100644
--- a/user-guide/0.17/compatibility/expressions/_category_template/math.html
+++ b/user-guide/0.17/compatibility/expressions/_category_template/math.html
@@ -543,6 +543,7 @@ under the License.
<li class="toctree-l3"><a class="reference internal" href="../../../../../contributor-guide/benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/profiling.html">Profiling</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/tracing.html">Tracing</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../../../../contributor-guide/expression-audits/index.html">Expression Audits</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
diff --git a/user-guide/0.17/compatibility/expressions/_category_template/misc.html b/user-guide/0.17/compatibility/expressions/_category_template/misc.html
index bfdfe2e3d2..0cb2ae42c0 100644
--- a/user-guide/0.17/compatibility/expressions/_category_template/misc.html
+++ b/user-guide/0.17/compatibility/expressions/_category_template/misc.html
@@ -543,6 +543,7 @@ under the License.
<li class="toctree-l3"><a class="reference internal" href="../../../../../contributor-guide/benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/profiling.html">Profiling</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/tracing.html">Tracing</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../../../../contributor-guide/expression-audits/index.html">Expression Audits</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
diff --git a/user-guide/0.17/compatibility/expressions/_category_template/string.html b/user-guide/0.17/compatibility/expressions/_category_template/string.html
index 60a8684135..c466884c96 100644
--- a/user-guide/0.17/compatibility/expressions/_category_template/string.html
+++ b/user-guide/0.17/compatibility/expressions/_category_template/string.html
@@ -543,6 +543,7 @@ under the License.
<li class="toctree-l3"><a class="reference internal" href="../../../../../contributor-guide/benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/profiling.html">Profiling</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/tracing.html">Tracing</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../../../../contributor-guide/expression-audits/index.html">Expression Audits</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
diff --git a/user-guide/0.17/compatibility/expressions/_category_template/struct.html b/user-guide/0.17/compatibility/expressions/_category_template/struct.html
index 36df4f8794..01cd0b3656 100644
--- a/user-guide/0.17/compatibility/expressions/_category_template/struct.html
+++ b/user-guide/0.17/compatibility/expressions/_category_template/struct.html
@@ -543,6 +543,7 @@ under the License.
<li class="toctree-l3"><a class="reference internal" href="../../../../../contributor-guide/benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/profiling.html">Profiling</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/tracing.html">Tracing</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../../../../contributor-guide/expression-audits/index.html">Expression Audits</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
diff --git a/user-guide/0.17/compatibility/expressions/_category_template/url.html b/user-guide/0.17/compatibility/expressions/_category_template/url.html
index 195e2154ad..d50dd29000 100644
--- a/user-guide/0.17/compatibility/expressions/_category_template/url.html
+++ b/user-guide/0.17/compatibility/expressions/_category_template/url.html
@@ -543,6 +543,7 @@ under the License.
<li class="toctree-l3"><a class="reference internal" href="../../../../../contributor-guide/benchmarking_spark_sql_perf.html">TPC-DS Benchmarking with spark-sql-perf</a></li>
</ul>
</details></li>
+<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/optimizing_expressions.html">Optimizing Scalar Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/profiling.html">Profiling</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../../../contributor-guide/tracing.html">Tracing</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../../../../contributor-guide/expression-audits/index.html">Expression Audits</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org