tur/perf
cached
(cached [p & [cache-size 1024])
cache pattern results within a cycle to avoid redundant evaluation.
| p | pattern to cache | |
| cache-size | number of cache buckets (default: 1024) |
Pattern<T> with memoised results for repeated time queries. (cached expensive-pat 512)
cached-ttl
(cached-ttl [p cache-size ttl])
cache pattern results with a time-to-live expiry.
| p | pattern to cache | |
| cache-size | number of cache buckets | |
| ttl | time-to-live in beats before an entry is re-evaluated |
Pattern<T> with TTL-based cache invalidation.
inline-pattern
(inline-pattern [p])
specialise simple patterns for reduced call overhead.
| p | pattern to inline |
An equivalent Pattern<T> with simpler internal structure where possible.
fuse-pattern
(fuse-pattern [p])
fuse consecutive pattern operations to reduce overhead.
| p | pattern to fuse |
Pattern<T> with fused operations where recognised.
CompiledPattern
(defstruct CompiledPattern [])
a pattern compiled to native code (conceptual).
compile-pattern
(compile-pattern [p])
attempt to compile a pattern to native code.
| p | pattern to compile |
CompiledPattern or nil if compilation is not supported.
eval-compiled
(eval-compiled [cp time])
evaluate a compiled pattern at a specific time.
| cp | CompiledPattern | |
| time | time in beats |
Pattern value (always 0.0 in this placeholder implementation).
LazyPattern<T>
(defstruct LazyPattern<T> [])
pattern whose construction is deferred until first use.
make-lazy-pattern
(make-lazy-pattern [thunk])
create a lazy pattern from a thunk.
| thunk | function that produces the pattern when first evaluated |
LazyPattern<T>.
eval-lazy
(eval-lazy [lp time])
evaluate a lazy pattern, constructing it on first use.
| lp | LazyPattern<T> | |
| time | time in beats |
Pattern value.
batch-eval
(batch-eval [p times])
evaluate a pattern at multiple times.
| p | pattern to evaluate | |
| times | vector of beat times |
Vector of pattern values corresponding to each time. (batch-eval my-pat [0.0 0.25 0.5 0.75])
batch-eval-process
(batch-eval-process [p times f])
evaluate a pattern at multiple times and transform results.
| p | pattern to evaluate | |
| times | vector of beat times | |
| f | function to apply to each result |
Vector of processed values.
optimize-pattern
(optimize-pattern [p & [passes [fuse-pattern inline-pattern cached])
apply a list of optimization passes to a pattern.
| p | pattern to optimize | |
| passes | list of optimization functions (default: fuse, inline, cache) |
Optimized Pattern<T>.
optimize
(optimize [p])
apply the standard optimization pipeline.
| p | pattern to optimize |
Optimized Pattern<T>.
optimize-aggressive
(optimize-aggressive [p])
apply an aggressive optimization pipeline including large cache.
| p | pattern to optimize |
Aggressively optimized Pattern<T>.
bench-pattern
(bench-pattern [p iterations & [warmup 10])
measure evaluation throughput for a pattern.
| p | pattern to benchmark | |
| iterations | number of timed iterations | |
| warmup | warmup iterations before timing (default: 10) |
Map with :total-ns, :avg-ns, and :iterations. (bench-pattern my-pat 10000)
patterns-equal?
(patterns-equal? [p1 p2 times & [tolerance 0.001])
compare two patterns for equality over a set of test times.
| p1 | first pattern | |
| p2 | second pattern | |
| times | vector of times to test | |
| tolerance | float tolerance for comparison (default: 0.001) |
true if all sample points agree within tolerance.
profile-pattern
(profile-pattern [p])
wrap a pattern to collect timing data on each call.
| p | pattern to profile |
Pattern<T> that accumulates call counts and total nanoseconds.
profile-stats
(profile-stats [profiled-fn])
retrieve profiling statistics from a profiled pattern.
| profiled-fn | profiled pattern function from profile-pattern |
Map with :calls, :total-time, and :avg-time.
zero-alloc-pattern
(zero-alloc-pattern [computation])
create a pattern guaranteed not to allocate in the hot path.
| computation | Beats -> T function with no allocations |
Pattern<T>.
zero-alloc-cycle
(zero-alloc-cycle [values])
zero-allocation cycling pattern over a pre-allocated vector.
| values | pre-allocated vector of values |
NumPattern with zero allocation.
zero-alloc-sine
(zero-alloc-sine [freq amp])
zero-allocation sine wave pattern.
| freq | frequency in cycles per beat | |
| amp | amplitude |
NumPattern with zero allocation.
PatternPool
(defstruct PatternPool [])
reusable pool of pattern instances.
pool-new
(pool-new [size factory])
create a pattern pool with pre-allocated instances.
| size | number of instances to pre-allocate | |
| factory | function producing a fresh pattern instance |
PatternPool.
pool-get
(pool-get [pool])
borrow a pattern from the pool (creates one if pool is empty).
| pool | PatternPool |
Pattern<T>.
pool-return
(pool-return [pool idx])
return a pattern to the pool by index.
| pool | PatternPool | |
| idx | index of the pattern to return |
simd-pattern-4
(simd-pattern-4 [p])
evaluate a pattern at 4 times simultaneously (conceptual).
| p | pattern to evaluate |
Function: vec<Beats> -> vec<T> evaluating all 4 times.
specialize-pattern
(specialize-pattern [p time-range])
constant-fold a pattern over a specific time range.
| p | pattern to specialise | |
| time-range | [start end] pair; if start == end, folds to a constant |
Specialised Pattern<T>.
specialize-constant
(specialize-constant [p])
evaluate a pattern once at time 0 and return a constant.
| p | pattern to specialise |
Pattern<T> always returning the value of p at time 0.
track-allocations
(track-allocations [p])
wrap a pattern to track GC allocations per evaluation.
| p | pattern to track |
Pattern<T> that measures allocation delta on each call.