Skip to content

Execute tensor product functions with RowFn - #9348

Draft
connortsui20 wants to merge 3 commits into
ct/row-fn-tensor-l2from
ct/row-fn-tensor-products
Draft

Execute tensor product functions with RowFn#9348
connortsui20 wants to merge 3 commits into
ct/row-fn-tensor-l2from
ct/row-fn-tensor-products

Conversation

@connortsui20

@connortsui20 connortsui20 commented Aug 11, 2026

Copy link
Copy Markdown
Member

Rationale for this change

Moves inner product and cosine similarity to the shared row executor. This removes duplicated batch machinery and prepares constant-dependent work once.

What changes are included in this PR?

Cosine similarity computes each batch-constant norm once. Inner product and cosine keep their Normalized reductions and authoritative stored-norm semantics. Tests cover dense, constant, nullable, vector, tensor, and normalized inputs.

Rust 1.97.1 one-CGU fat-LTO measurements show the width-256 dense inner product within 4.1% of develop; most other product paths improve by 14–92%, with the largest gains on constant operands and narrow vectors.

What APIs are changed? Are there any user-facing changes?

There are no public API or behavior changes. Both functions implement RowFn and receive the standard scalar-function vtable automatically.

@codspeed-hq

codspeed-hq Bot commented Aug 11, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 10.65%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 18 improved benchmarks
❌ 70 regressed benchmarks
✅ 1906 untouched benchmarks
🆕 57 new benchmarks
⏩ 89 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation case_when_nary_10_conditions[10000] 745.7 µs 2,008 µs -62.86%
Simulation case_when_nary_equality_lookup[10000] 514.8 µs 1,151.7 µs -55.3%
Simulation case_when_nary_early_dominant[10000] 382.4 µs 765.4 µs -50.04%
Simulation case_when_nary_3_conditions[10000] 383.8 µs 766.7 µs -49.93%
Simulation case_when_all_false[100000] 1.1 ms 2.1 ms -49.41%
Simulation case_when_all_true[100000] 1.1 ms 2.1 ms -49.28%
Simulation case_when_simple[100000] 1.2 ms 2.3 ms -48.87%
Simulation case_when_without_else[100000] 1.2 ms 2.4 ms -47.14%
Simulation case_when_nary_10_conditions[1000] 401.2 µs 693.7 µs -42.16%
Simulation case_when_all_false[10000] 210.1 µs 341.6 µs -38.51%
Simulation case_when_all_true[10000] 214.5 µs 347.6 µs -38.29%
Simulation case_when_simple[10000] 242.3 µs 372.6 µs -34.96%
Simulation case_when_without_else[10000] 258.7 µs 392.1 µs -34.01%
Simulation case_when_nary_equality_lookup[1000] 310.2 µs 467.7 µs -33.67%
Simulation bench_compare_sliced_dict_primitive[(5000, 10000)] 185.3 µs 271.7 µs -31.81%
Simulation case_when_nary_early_dominant[1000] 225.2 µs 321.9 µs -30.04%
Simulation bench_compare_sliced_dict_primitive[(3333, 10000)] 160.4 µs 228.7 µs -29.89%
Simulation bench_compare_sliced_dict_primitive[(7500, 10000)] 246.7 µs 349.1 µs -29.34%
Simulation case_when_nary_3_conditions[1000] 227.4 µs 321.6 µs -29.29%
Simulation bench_compare_sliced_dict_primitive[(2500, 10000)] 147.5 µs 206.3 µs -28.49%
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ct/row-fn-tensor-products (6a91edb) with develop (204d1d4)2

Open in CodSpeed

Footnotes

  1. 89 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on ct/row-fn-tensor-l2 (d5d1dc7) during the generation of this report, so develop (204d1d4) was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@connortsui20
connortsui20 force-pushed the ct/row-fn-tensor-products branch from 3285a39 to 8b31bba Compare August 11, 2026 16:04
@connortsui20
connortsui20 marked this pull request as ready for review August 11, 2026 16:05
@connortsui20
connortsui20 marked this pull request as draft August 11, 2026 16:24
@connortsui20
connortsui20 force-pushed the ct/row-fn-tensor-products branch 2 times, most recently from 19d16dc to cb67153 Compare August 11, 2026 17:35
@connortsui20
connortsui20 force-pushed the ct/row-fn-tensor-products branch from cb67153 to 32bd4da Compare August 11, 2026 19:36
@connortsui20

Copy link
Copy Markdown
Member Author

Here are the local tensor-product benchmark results from the final Rust 1.97.1 run.

The comparison used a develop baseline with benchmark-only backfills (1edd0fca) and the full RowFn stack (8ca9fc73). Later stack layers do not change tensor-product source, but unrelated code-placement effects can still affect these binaries.

The machine was an AMD Ryzen 9 7950X running Linux. The build used rustc 1.97.1, LLVM 22.1.6, one CGU, fat LTO, and -C target-cpu=native. Each target used two warm runs and seven alternating measured pairs. Each process used 100 samples with a 0.25–0.5 second measurement window on CPU 4.

Negative changes are faster. The values are medians across the seven paired runs.

Width-256 dense inner products remain within 4.11%. Narrow, constant, and nullable-constant product cases improve by 14.68–91.92%. Every cosine-similarity case improves, while the Normalized controls remain within 1.34%.

Inner product: 15 cases
Benchmark Baseline RowFn stack Change
non_nullable/256 5.119 µs 5.339 µs +4.11%
nullable/256 5.899 µs 5.689 µs -3.73%
non_nullable/32 4.019 µs 3.429 µs -14.68%
nullable/32 4.809 µs 3.779 µs -21.63%
constant_x_column/256 96.580 µs 30.980 µs -67.83%
column_x_constant/256 96.450 µs 27.610 µs -71.56%
column_x_nullable_constant/256 97.440 µs 24.460 µs -74.92%
nullable/2 31.490 µs 7.659 µs -75.71%
non_nullable/2 31.620 µs 7.329 µs -76.79%
column_x_nullable_constant/2 112.600 µs 11.750 µs -89.59%
column_x_constant/2 110.500 µs 11.440 µs -89.66%
constant_x_column/2 117.200 µs 11.540 µs -90.20%
constant_x_column/32 88.670 µs 7.869 µs -91.14%
column_x_constant/32 86.890 µs 7.349 µs -91.55%
column_x_nullable_constant/32 89.320 µs 7.239 µs -91.92%
Cosine similarity: 15 cases
Benchmark Baseline RowFn stack Change
column_x_extension_constant/256 34.630 µs 25.460 µs -26.48%
column_x_extension_constant/32 8.759 µs 6.199 µs -29.31%
constant_x_column/256 44.820 µs 28.290 µs -36.88%
column_x_constant/256 44.940 µs 24.690 µs -45.04%
column_x_column/32 4.569 µs 2.289 µs -49.68%
column_x_column/256 5.359 µs 2.279 µs -57.47%
column_x_extension_constant/2 16.460 µs 5.999 µs -63.86%
column_x_nullable_constant/256 68.540 µs 21.860 µs -68.02%
column_x_column/2 17.850 µs 4.329 µs -75.78%
constant_x_column/32 28.570 µs 6.349 µs -77.62%
column_x_constant/32 28.770 µs 5.849 µs -79.41%
column_x_constant/2 36.100 µs 5.679 µs -84.27%
constant_x_column/2 37.210 µs 5.849 µs -84.33%
column_x_nullable_constant/32 53.640 µs 5.809 µs -88.97%
column_x_nullable_constant/2 65.410 µs 5.989 µs -90.89%
Normalized-array controls: 6 cases
Benchmark Baseline RowFn stack Change
nullable/32 8.179 µs 8.279 µs +1.34%
nullable/256 8.089 µs 8.119 µs +0.87%
non_nullable/2 17.260 µs 17.340 µs +0.58%
nullable/2 18.010 µs 18.160 µs +0.50%
non_nullable/32 7.529 µs 7.579 µs +0.40%
non_nullable/256 7.439 µs 7.409 µs -0.27%

@connortsui20
connortsui20 force-pushed the ct/row-fn-tensor-products branch from 32bd4da to d1277e6 Compare August 12, 2026 15:24
@connortsui20
connortsui20 force-pushed the ct/row-fn-tensor-products branch from d1277e6 to b563ade Compare August 12, 2026 17:53
@connortsui20
connortsui20 force-pushed the ct/row-fn-tensor-products branch from b563ade to 05091c6 Compare August 12, 2026 18:10
@connortsui20
connortsui20 force-pushed the ct/row-fn-tensor-products branch 2 times, most recently from a83f456 to fda2d31 Compare August 12, 2026 19:23
@connortsui20
connortsui20 force-pushed the ct/row-fn-tensor-products branch from fda2d31 to e915ffd Compare August 12, 2026 20:26
@connortsui20
connortsui20 force-pushed the ct/row-fn-tensor-products branch from e915ffd to 7c4edbf Compare August 12, 2026 20:50
@connortsui20
connortsui20 force-pushed the ct/row-fn-tensor-products branch from 7c4edbf to fa948f8 Compare August 12, 2026 21:03
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
@connortsui20
connortsui20 force-pushed the ct/row-fn-tensor-products branch from fa948f8 to 6a91edb Compare August 12, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant