Skip to content

defk-vcx.2: measure Elixir mode at small sizes; it is never the fast side - #79

Merged
DanielLuning merged 1 commit into
mainfrom
defk-vcx.2/elixir-mode-small-sizes
Oct 22, 2026
Merged

DanielLuning merged 1 commit into
mainfrom
defk-vcx.2/elixir-mode-small-sizes

Conversation

@DanielLuning

Copy link
Copy Markdown
Owner

What changed

A new bench, bench/elixir_mode.exs, times each of five kernels three ways at 1 B to 1 KiB: the native kernel, its Elixir mode (__defk_elixir__/2) and the example's optimised Elixir. Two read-only hash kernels (xxh64, SipHash-2-4 from hashes.exs), one kernel that allocates and writes (ws_mask), and two kernels with no loop (add, clamp). The result is recorded as docs/performance.md 5.14, with a row in the myths table.

The question (defk-vcx.2): defk generates Elixir beside the C for each kernel, so could a call switch to that Elixir below the crossover size? Answer: no. Elixir mode's rule (test oracle, never production, never a baseline) stands; the entry says so.

Results

Two quiet runs (other CPU 0.3-0.9 cores), medians of 7 interleaved rounds of 20,000 calls, ns per call:

kernel size kernel Elixir mode Elixir (opt.) mode/kernel mode/Elixir
xxh64 1 B 36 603 178 17x 3.4x
xxh64 1 KiB 80 18,100 9,437 227x 1.9x
siphash24 1 B 40 3,002 1,717 76x 1.7x
ws_mask 1 B 83 566 82 6.8x 6.9x
ws_mask 1 KiB 233 145,500 707 624x 206x
add (no loop) 17 248 3 15x 79x
clamp (no loop) 19 222 5 12x 48x

Elixir mode's entry alone costs ~230 ns (argument checks, the __defk_stats__ NIF call for the budget, the process-dictionary budget), 10x a kernel call. Its loops are 1.6-3.4x the optimised Elixir on reads (a helper call per element) and 100-200x on writes (a new binary per write).

The ticket's threshold for a decision ticket (Elixir mode within ~2x of the optimised Elixir) is met by the two read-only hashes from 64 B up, but a switch would replace the kernel call, and the kernel is 7-17x faster than Elixir mode at 1 B and 12-15x on a kernel with no loop at all. There is no size where the generated Elixir is the fast side, so no decision ticket is filed. Owner's call if you read the threshold differently.

How it was checked

mix ci on the M-series laptop: 2305 passed, 815 excluded. The bench checks agreement of the three sides on every input before timing. No test added: the bench is not under test/.

  • Touches a promised surface? No: a bench script and the performance guide.
  • Touches test/stability/? No.

…side

A bench (bench/elixir_mode.exs) times two read-only hash kernels, one
kernel with writes and two no-loop kernels three ways: the native kernel,
its Elixir mode and the example's optimised Elixir, at 1 B to 1 KiB.
Elixir mode is 7-17x the kernel at 1 B and 12-15x on a kernel with no
loop (its entry alone is ~230 ns), 1.6-3.4x the optimised Elixir on
reads and 100-200x on writes. No size-based switch; no decision ticket.
Recorded as docs/performance.md 5.14.
DanielLuning pushed a commit that referenced this pull request Oct 22, 2026
…nd docs/performance.md 5.14. Elixir mode is 7-17x the kernel at 1 B, 12-15x on a no-loop kernel (entry ~230 ns), 1.6-3.4x the optimised Elixir on reads, 100-200x on writes. No size-based switch, no decision ticket filed; the ticket stays in progress until the merge."
DanielLuning pushed a commit that referenced this pull request Oct 22, 2026
…ters rank in declaration order, so base <= length(x) bounds base and base + idx[j] drops its overflow check; the table of checks and the numbers are docs/performance.md 6.45. Guarded gather loop 0.75 ns per term (was 0.9-1.1); compiler +0.5% work. Stays in progress until the merge."
DanielLuning pushed a commit that referenced this pull request Oct 22, 2026
…one countdown instead of two counters; fuzzy_search +30% -> +16%, Keccak unchanged (its 12 spills are the saves (8) and the resume dispatch (3), not the counters; 1.3x quiet). Variants V2 (charge on entry) and V3 (no bookkeeping register) measured, not adopted. Tick gap unchanged, mix ci green. docs/performance.md 6.46. Stays in progress until the merge."
@DanielLuning
DanielLuning merged commit ecaac92 into main Oct 22, 2026
2 checks passed
@DanielLuning
DanielLuning deleted the defk-vcx.2/elixir-mode-small-sizes branch October 22, 2026 10:37
DanielLuning added a commit that referenced this pull request Oct 22, 2026
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