Performance Optimization

Measure first: --profile, now timing, the Telemetry module.

Startup time: precompilation of modules happens automatically (.precomp directories). Keep scripts thin and put code in modules so it's precompiled.

Use native types (int, num, native arrays) in tight numeric loops.

Avoid unnecessary laziness and boxing in hot paths. eager can help when you know you need all results. Use .List/.Array judiciously.

Prefer built-in methods (.sum, .elems, .grep, .comb) over hand-written loops. They're optimized in the core.

String building: use join, ~= in moderation, or collect into arrays.

Regex/grammar performance: use tokens (:ratchet) to avoid backtracking, anchor patterns, prefer LTM-friendly alternations, and avoid overly generic .*.

Multi-dispatch caches make repeated calls fast. Avoid where constraints in the hottest calls (they're checked at run time).

Parallelism: hyper/race/start for CPU-bound work across cores. Batch tiny tasks.

Avoid run-time EVAL in loops. Avoid excessive dynamic variable lookups in hot code.

Use NativeCall for performance-critical algorithms available in C libraries.

Upgrade Rakudo: each monthly release includes optimizations. The new dispatch mechanism (2021+) and ongoing RakuAST work have improved performance substantially.