Eliminate lazy initialization overhead from interpreter hot paths (~8% faster)#2346
Merged
Merged
Conversation
…% 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 `_initialized` field and `Initialize()` 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>
lahma
enabled auto-merge (squash)
March 22, 2026 13:10
This was referenced Mar 23, 2026
This was referenced Jun 8, 2026
This was referenced Jun 29, 2026
This was referenced Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_initializedbool field and branch fromJintStatement.Execute()— the interpreter's hottest path — by moving allInitialize()work into constructorsJintBinaryExpression,JintCallExpression,JintMemberExpression, etc.)EvaluationContextdependency fromExpressionCache.Initialize()so call/new/array/object expression caches can also be built eagerlyJintStatementListandJintSwitchBlockarray construction to constructorsRationale
Every
JintStatement.Execute()call checkedif (!_initialized)on every invocation — not just the first. In tight loops this branch accumulates measurably. Since none of theInitialize()methods actually used theEvaluationContextparameter (they only calledJintExpression.Build(),JintStatement.Build(), andProbablyBlockStatement()), moving the work to constructors is safe and eliminates the per-execution branch.Benchmark results (SunSpider, 26 tests, lower is better)
_initializedelimination_initializedeliminationBiggest individual improvements:
bitops-nsieve-bits-10%,date-format-xparb-10%,math-cordic-8.9%,crypto-aes-7.8%,crypto-sha1-7.1%Test plan
🤖 Generated with Claude Code