Description
Every function call creates a new Environment (heap-allocated Rc<RefCell<HashMap<String, Binding>>>>), binds this, creates an arguments object, and binds each parameter. For mandreel's 849 emulated C functions (each taking a single sp argument), this per-call overhead is substantial.
Proposed optimizations
-
Environment pooling: reuse Environment objects from a freelist instead of allocating new ones. Clear and repopulate bindings instead of allocating a new HashMap.
-
Pre-sized Environment: for functions with known parameter counts, pre-allocate the HashMap with the right capacity to avoid rehashing.
-
Skip arguments object creation: most functions don't use arguments. Lazily create the arguments object only when arguments is actually referenced.
-
Fast parameter binding: for simple parameter patterns (just identifiers, no defaults/destructuring), bind parameters with a single HashMap insert instead of the full bind_pattern machinery.
Motivation
Mandreel (#54) calls thousands of small functions in tight loops. Each function _something(sp) { ... } call creates an Environment, binds sp, creates an unused arguments object, etc. Reducing this fixed per-call cost would significantly improve throughput.
References
Description
Every function call creates a new
Environment(heap-allocatedRc<RefCell<HashMap<String, Binding>>>>), bindsthis, creates an arguments object, and binds each parameter. For mandreel's 849 emulated C functions (each taking a singlespargument), this per-call overhead is substantial.Proposed optimizations
Environment pooling: reuse
Environmentobjects from a freelist instead of allocating new ones. Clear and repopulate bindings instead of allocating a new HashMap.Pre-sized Environment: for functions with known parameter counts, pre-allocate the HashMap with the right capacity to avoid rehashing.
Skip arguments object creation: most functions don't use
arguments. Lazily create the arguments object only whenargumentsis actually referenced.Fast parameter binding: for simple parameter patterns (just identifiers, no defaults/destructuring), bind parameters with a single HashMap insert instead of the full
bind_patternmachinery.Motivation
Mandreel (#54) calls thousands of small functions in tight loops. Each
function _something(sp) { ... }call creates an Environment, bindssp, creates an unused arguments object, etc. Reducing this fixed per-call cost would significantly improve throughput.References