Eliminate lazy initialization overhead from interpreter hot paths (~8% faster) by lahma · Pull Request #2346 · sebastienros/jint (original) (raw)
…% faster)
Remove _initialized bool check from every statement execution and expression
evaluation by moving initialization work into constructors. Previously, each
JintStatement.Execute() call checked if (!_initialized) on every invocation,
adding a branch to the interpreter's hottest path. Since none of the Initialize()
methods actually needed the EvaluationContext, moving them to constructors is safe.
Changes:
- Remove
_initializedfield andInitialize()virtual method from JintStatement base - Move initialization to constructors in all 17 statement subclasses
- Move initialization to constructors in 12 expression types (JintBinaryExpression, JintCallExpression, JintMemberExpression, JintUpdateExpression, etc.)
- Remove EvaluationContext dependency from ExpressionCache.Initialize()
- Move JintStatementList Pair[] construction to constructor
- Move JintSwitchBlock case array construction to constructor
- Handle debug mode FastResolve check at execution time instead of init time
SunSpider benchmark: 2,693ms → 2,474ms (-8.2%, 26 tests) Test262: 0 failures, 95,798 passing
Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com