Skip to content

2.1.9

Latest

Choose a tag to compare

@dsblank dsblank released this 25 Jul 17:22
· 2 commits to master since this release

What's Changed

  • Replaced the environment cons-chain's O(depth) walk for
    lookup-value-by-lexical-address/lookup-binding-by-lexical-address
    with a persistent vector (32-way trie with a tail buffer -- the same
    structure Clojure/Scala use for fast indexed access with full
    structural sharing), giving O(1) lookup for any environment nested
    past a depth-8 threshold. Found via PyPy's own JIT trace log, which
    showed search_frame/lookup_value_by_lexical_address among the
    hottest functions in the classic trampoline. Confirmed the O(depth)
    cost directly before fixing it (19.16us/iteration at nesting depth 1
    up to 45.46us/iteration at depth 800, a clean linear fit); eliminates
    that scaling entirely for deeply nested lets/closures. Building the
    vector unconditionally measured as a ~13-15% regression on shallow
    naive recursion like fib; threshold-gating it got that down to
    ~5-10%, residual only under (use-jit #f) -- JIT'd code is unaffected
    in every configuration. extend, make-empty-environment,
    make-initial-environment, lookup-value-by-lexical-address,
    lookup-binding-by-lexical-address, and set-first-frame! in
    environments-cps.ss are now define-native. See
    README-PERFORMANCE.md's new Phase 10 section for the full account,
    including two real bugs found while implementing it (the
    register-machine compiler's calling convention for define-native
    callees, and top-level define replacing the global frame in place
    via set-first-frame! rather than extend). 7 new pinned regression
    tests in tests/test_env_lexaddr_vec.py.
  • Verified PyPy 7.3.15 compatibility: full test suite passes unmodified,
    no code changes needed. The JIT compiles Scheme closures to Python
    source via compile()/exec() -- a Python-language builtin, not a
    CPython API -- so PyPy's own tracing JIT stacks with it rather than
    competing (~2.1-2.4x on non-tail recursion, ~60x on tail loops,
    steady-state).
  • Made calysto_scheme/__init__.py's Jupyter-kernel import and
    Scheme.py's yasi import lazy -- both previously ran on every
    from calysto_scheme import scheme regardless of whether the kernel
    or REPL pretty-printing was ever used. Cuts steady-state import time
    ~24x on CPython (0.216s -> 0.009s) and ~25x on PyPy
    (0.567s -> 0.022s).

Full Changelog: v2.1.8...v2.1.9