Skip to content

defk-9p6.29: threshold_cross, an early-exit loop in Elixir, a kernel and Nx defn with EXLA - #76

Merged
DanielLuning merged 4 commits into
mainfrom
defk-9p6.29/threshold-cross
Oct 20, 2026
Merged

DanielLuning merged 4 commits into
mainfrom
defk-9p6.29/threshold-cross

Conversation

@DanielLuning

Copy link
Copy Markdown
Owner

Merge #74, then #75, first. This branch builds on defk-9p6.30/tape-csv (the same tables, README rows and scoreboard).

What changed

  • New example examples/threshold_cross.exs: the first packet whose running total passes a byte budget. The loop is sequential, stops early and is integer-exact. It is written four ways: Elixir (E1, E2 with four packets per clause), a kernel (Enum.reduce_while), defn with while and a stop flag, and defn with cumulative_sum + argmax. EXLA runs on resident tensors, one Nx.Defn.compile/3 per shape.
  • The example also measures per-call times from 16 to 16M packets, 1 and 48 concurrent callers, the tick gap on one scheduler, and 300 calls of changing length (EXLA's jit cold and warm, and the power-of-two bucket workaround).
  • docs/scope.md: the sentence "not measured against EXLA yet" is replaced by the numbers. docs/research/nx-boundary.md: the open question is now a list of measured numbers. docs/performance.md 3.10. _tables.exs, the READMEs (regenerated), an example bullet.
  • examples/scoreboard.json: a quiet row at 3602f17 (--fresh from a clean tree).

Results

Per call, µs, with the budget passed at 25%. Two runs; the first shared the machine with a mix ci, so these are provisional.

n E2 defk EXLA while EXLA scan
16 0.14-0.16 0.05 40-48 37-126
4096 1.03-1.09 0.36-0.42 40-41 50
64k 15.7-17.0 4.4-4.6 62-63 154-168
16M 4336-4467 1473-1478 4272-4359 24780-25650
  • Verdict (64k packets, against Elixir): 2.5-3.4x, good. EXLA while is 11.7-13.2x slower than the kernel.
  • Kernel against EXLA: the kernel is faster at every size, from about 790x at 16 packets to 2.9x at 16M.
  • Elixir against EXLA: optimised Elixir beats EXLA while up to 1M packets and is level at 16M. The cumulative_sum form is slower than Elixir at every size.
  • Concurrency (4096 packets, calls per second): EXLA goes from 24.5k (1 process) to 46.8k (48 processes); the kernel from 3.2M to 22.3M.
  • Variable length: EXLA compiles each new length, about 6.4 ms each (1.9 s cold, 20 ms warm). Buckets bring it to 0.25 s cold and 36 ms warm. Elixir takes 0.8-1.0 ms, the kernel 0.4 ms.
  • Tick gap: about 2 ms on every side. EXLA's dirty NIF does not hold a normal scheduler.

How it was checked

  • mix ci green in the worktree (2305 passed).

  • Agreement: all sides give the same index on 80 inputs, including the kernel's Elixir mode. An empty input works in the kernel; Nx.from_binary(<<>>) raises.

  • Touches a promised surface (kernel subset, runtime contract, public API, error codes)? Then a CHANGELOG.md entry, and a deprecation for a rename or removal (docs/guides/stability.md).

  • Touches test/stability/? A frozen file is never edited; a release adds a directory (docs/agents/stability.md).

DanielLuning pushed a commit that referenced this pull request Oct 20, 2026
@DanielLuning
DanielLuning merged commit f983d5e into main Oct 20, 2026
2 checks passed
@DanielLuning
DanielLuning deleted the defk-9p6.29/threshold-cross branch October 20, 2026 19:37
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