Skip to content

Optimize function call overhead: Environment pooling and fast argument binding #73

Description

@pmatos

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

  1. Environment pooling: reuse Environment objects from a freelist instead of allocating new ones. Clear and repopulate bindings instead of allocating a new HashMap.

  2. Pre-sized Environment: for functions with known parameter counts, pre-allocate the HashMap with the right capacity to avoid rehashing.

  3. Skip arguments object creation: most functions don't use arguments. Lazily create the arguments object only when arguments is actually referenced.

  4. 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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions