-
-
Notifications
You must be signed in to change notification settings - Fork 116
Open
Labels
Description
General
- Constant propagation (substituting constants in where possible)
- Constant folding (compile-time eval of pure expressions with literals)
- Requires tracking pure fns
- Share closure contexts by having common value ordering across mutually recursive functions
- Guaranteed named recursion TCO
- AST-level function inlining (requires interop to be a big win)
- Clojure uses this to inline
RT.get,Numbers.multiply, etc - Don't duplicate body in inline meta; just use
:inline true- Then we need to deal with merging fn bodies; use an implicit
letto create the params by name
- Then we need to deal with merging fn bodies; use an implicit
- Use a recursive count on the fn body to do cost analysis
- Clojure uses this to inline
Function attribute tracking
- Pure (doesn't modify any global memory) - https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-pure-function-attribute
- Const (doesn't read or modify any global memory) - https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-const-function-attribute
- Captures a parameter (note which params are captured)
- Can throw
Vars
- If a var has
:jank/static? truemeta, deref + store it in the module's global ctor and never deref it again (superseded by direct linking)- Also, in each function, only load it once
Dead code elimination
- Dead branches
- Pure statements
Boxing
- Arithmetic unboxing for numeric locals
- Unboxed numeric function parameters (requires either hinting or monomorphization)
- Unboxing for non-numeric locals (strings, maps, etc -- a la Project Valhalla)
- If the local is never returned or closed over, it can be on the stack
- Requires tracking capturing fns
- C# does some of this: https://em-tg.github.io/csborrow/
- If a local function is not captured, it can be monomorphized for each call
Startup
- Group all fns into a single module to load
- Box globals in static memory, not with the GC
- Add CLI option to elide meta (see Clojure's elide-meta)
- Two phase jank compilation which bakes in core libs during the second phase (i.e. instant startup)
Form rewriting
- Auto-transient
- Auto-transducer
- Zero-cost map destructuring (see here)
- General loop unrolling
- Specific loop unrolling (i.e.
get-in) - Faster
strusage (a la stringer) - Replace
firstandsecondon knowncountabletypes withnth - Change recursion into
loop/recur - Auto record creation, for map literals
IR-specific
- Don't require boxing strings for reading globals #301
- Don't put meta into globals
- Optimize the passes we run and offer different levels
- Put
thisinto closure context for named recursion- Can also work by forcing normal functions into closures if they're named recursive
Interop
- Avoid repeated trait conversions for the same value
AOT-only
- Direct linking (dynamic call)
- Direct linking (direct call)
- Unused var removal (includes defns)
- Flag to elide var meta
- Remove unused args from fns
- Unity build (i.e. one object file for all namespaces)
- Automatic inlining
- Given that we have inlining based on meta, defined above, if we're compiling with direct linking we can automatically inline any fn which passes cost analysis
Runtime
- Use immer to merge maps
References
- LLVM front-end tips: https://llvm.org/docs/Frontend/PerformanceTips.html
- Optimizing compiler: https://en.wikipedia.org/wiki/Optimizing_compiler
- Clojure optimization discussion: https://clojureverse.org/t/do-clojure-still-have-rooms-to-improve-at-compiler-level/7802
- Orbit, optimizing Scheme compiler: https://www.cs.purdue.edu/homes/suresh/502-Fall2008/papers/orbit.pdf
- Lisp compiler optimizations: https://healeycodes.com/lisp-compiler-optimizations
Reactions are currently unavailable