Skip to content

perf: elide function environment when only this escapes into arrows#5019

Open
hansl wants to merge 4 commits intoboa-dev:mainfrom
hansl:this-escaped-only
Open

perf: elide function environment when only this escapes into arrows#5019
hansl wants to merge 4 commits intoboa-dev:mainfrom
hansl:this-escaped-only

Conversation

@hansl
Copy link
Contributor

@hansl hansl commented Mar 12, 2026

When a non-arrow function's sole reason for needing a DeclarativeEnvironment with FunctionSlots is that this escapes into inner arrow functions, skip the Gc environment allocation entirely. Instead, resolve this at arrow-creation time and store it directly on the arrow's OrdinaryFunction via a new SetArrowLexicalThis opcode.

Also includes follow-up fixes for the linked-list EnvironmentStack: promote inline environments before cloning in eval, generator suspend, JSON parse, module execution, and environment binding ops.

When a non-arrow function's sole reason for needing a
`DeclarativeEnvironment` with `FunctionSlots` is that `this` escapes
into inner arrow functions, skip the Gc environment allocation entirely.
Instead, resolve `this` at arrow-creation time and store it directly on
the arrow's `OrdinaryFunction` via a new `SetArrowLexicalThis` opcode.

Also includes follow-up fixes for the linked-list EnvironmentStack:
promote inline environments before cloning in eval, generator suspend,
JSON parse, module execution, and environment binding ops.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hansl hansl requested a review from a team as a code owner March 12, 2026 21:29
@github-actions
Copy link

github-actions bot commented Mar 12, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 49,902 49,902 0
Ignored 2,222 2,222 0
Failed 839 839 0
Panics 0 0 0
Conformance 94.22% 94.22% 0.00%

Tested main commit: 7eb60775351e9335fe13e457f398a879113ba759
Tested PR commit: 4652b2fb10994af68ab624c5bc41f1525216cad9
Compare commits: 7eb6077...4652b2f

@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 64.63654% with 180 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.70%. Comparing base (6ddc2b4) to head (4652b2f).
⚠️ Report is 882 commits behind head on main.

Files with missing lines Patch % Lines
core/engine/src/environments/runtime/mod.rs 66.03% 143 Missing ⚠️
core/engine/src/vm/opcode/set/name.rs 0.00% 10 Missing ⚠️
core/engine/src/vm/opcode/get/function.rs 0.00% 9 Missing ⚠️
core/engine/src/bytecompiler/mod.rs 37.50% 5 Missing ⚠️
core/engine/src/builtins/function/mod.rs 50.00% 4 Missing ⚠️
core/engine/src/bytecompiler/function.rs 70.00% 3 Missing ⚠️
core/engine/src/vm/code_block.rs 57.14% 3 Missing ⚠️
core/ast/src/scope.rs 66.66% 1 Missing ⚠️
core/ast/src/scope_analyzer.rs 87.50% 1 Missing ⚠️
core/engine/src/vm/flowgraph/mod.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5019       +/-   ##
===========================================
+ Coverage   47.24%   58.70%   +11.46%     
===========================================
  Files         476      559       +83     
  Lines       46892    61765    +14873     
===========================================
+ Hits        22154    36261    +14107     
- Misses      24738    25504      +766     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jedel1043 jedel1043 added A-Performance Performance related changes and issues C-VM Issues and PRs related to the Boa Virtual Machine. Waiting On Author Waiting on PR changes from the author labels Mar 16, 2026
@jedel1043 jedel1043 added this to the v1.0.0 milestone Mar 16, 2026
@jedel1043 jedel1043 added Waiting On Review Waiting on reviews from the maintainers and removed Waiting On Author Waiting on PR changes from the author labels Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Performance Performance related changes and issues C-VM Issues and PRs related to the Boa Virtual Machine. Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants