Repository navigation
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
showedsearch_frame/lookup_value_by_lexical_addressamong 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 nestedlets/closures. Building the
vector unconditionally measured as a ~13-15% regression on shallow
naive recursion likefib; 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, andset-first-frame!in
environments-cps.ssare nowdefine-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 fordefine-native
callees, and top-leveldefinereplacing the global frame in place
viaset-first-frame!rather thanextend). 7 new pinned regression
tests intests/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 viacompile()/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'syasiimport lazy -- both previously ran on every
from calysto_scheme import schemeregardless 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