Part V — The Modern Experience Layer · Chapter 34 · Lesson 2 of 2
A numerics fast path you can actually use
The JIT chapter showed the mechanism; this lesson is judgment: when to reach for it, and what to do instead when it doesn't apply.
What actually gets faster
- Numeric kernels — reductions, maps over arrays, arithmetic-heavy transforms. Two to ten times on tight loops is realistic; some kernels go further.
- Dispatch-heavy dynamic code — inline caching collapses repeated method dispatch to a compare-and-branch. Dynamic OO-shaped code becomes branch-predictable.
- Loop-invariant expressions — hoisted computations run once instead of per iteration.
What does not
- I/O waits, network, disk. The JIT does not speed up a slow database, a remote API or an unindexed query.
- Cold code. First execution traces first, compiles second — cold paths are slower, not faster.
- Megamorphic call sites. Hundreds of distinct receiver types defeat inline caches; restructure or accept the interpreter.
- Branchy, data-dependent control flow — traces favor straight-line hot paths; random branching produces trace explosions, not speed.
The bigger lever for analytics: Arrow and DuckDB (v1.6.0)
let backend = analysis.preferred_backend() # PythonBackend or DuckDBBackend
let plan = analysis.create_query_plan("""
SELECT city, SUM(amount) AS revenue
FROM orders
WHERE status = 'paid'
GROUP BY city
""")
print plan
For genuinely large analytics, the Arrow/DuckDB path dominates anything the JIT gives a scalar interpreter: predicate/projection pushdown, vectorized execution, out-of-core frames, parallel aggregation. The JIT optimizes your per-row code; the Arrow backend optimizes your data movement. Use both, and know which lever you are pulling when a query is slow.
Measurement discipline
let report = analysis.benchmark_compare([before_run, after_run])
print report.speedup
Three rules that separate real optimization from vibes. First, benchmark on your workload — yours, with your data sizes, your access patterns. Second, archive baselines so regressions surface as deltas, not as vague slowness complaints three weeks later. Third, report medians with spread, never best-of-N; best-of-N is how bad changes get merged.
Version note
Version note. In v2.0.0, optimize_instructions was effectively hints you could ignore. In v2.2.0 it is a real pass pipeline, wired into the analysis, stats and numerics namespaces, and applied automatically on supported paths. If your v0.63-era code called loop_unroll_hint for its side effects, those calls now fold into the pipeline.
Where this leaves the 1.0-era performance story
- Interpreter first for debuggability; VM for production; JIT passes for hot kernels; Arrow/DuckDB for data-shaped work. Each layer is opt-in, measureable and reversible.
- The conformance and differential gates apply to the JIT exactly as they do to the interpreter — if a pass miscompiles, the build fails, not the user.
Guided practice
- Identify one scalar hot path and one analytics-shaped path in your project; fix the first with JIT-friendly structure, the second with the Arrow backend.
- Add warmup to your benchmark harness; compare numbers with and without it — the difference is the JIT tax you never see in production.
- Write down the dataset size and shape you benchmarked on, next to the speedup number. If you cannot reproduce it next quarter, it never happened.