Skip to main content

Module jit

Module jit 

Source
Expand description

JIT compilation for hot expression paths.

JitCompiler wraps a standard compilation pipeline and tracks expression usage frequency. When an expression exceeds JitCompiler::hot_threshold compilations it is promoted to the “hot path”: the expression is re-optimised more aggressively with OptimizationPipeline (aggressive preset) before compilation, and the result is stored as a pre-computed Arc<EinsumGraph>. All subsequent compilations of the same hot expression return the cached graph in O(1) without re-running the optimizer or compiler.

§Design notes

Expression identity is determined via the Debug representation of the TLExpr — a deterministic structural fingerprint. This avoids requiring Hash or PartialEq on TLExpr while still being correct for the intended use case (repeated compilation of the same logical rule).

The call-count map stores a clone of the originating TLExpr alongside its hit count so that, when the threshold is crossed, the original expression is available for the extra optimization pass.

§Thread safety

Both the hot-path cache and the call-count map are guarded by a single Mutex. The cold path (compilation itself) is performed outside the lock so that concurrent cold compilations of different expressions do not serialise on I/O-heavy optimizer work.

Structs§

JitCompiler
JIT compiler with hot-path detection and pre-optimized graph caching.
JitStats
Statistics snapshot from a JitCompiler.

Enums§

JitError
Errors emitted by JitCompiler.