Skip to content

perf: use FxHashSet for O(1) name lookups in declaration instantiation - #5024

Merged
jedel1043 merged 6 commits into
boa-dev:mainfrom
tkshsbcue:perf/hashset-declaration-lookups
Aug 30, 2026
Merged

jedel1043 merged 6 commits into
boa-dev:mainfrom
tkshsbcue:perf/hashset-declaration-lookups

Conversation

@tkshsbcue

Copy link
Copy Markdown
Contributor

Description

This PR replaces Vec with FxHashSet for name-tracking collections in the bytecode compiler's declaration instantiation functions, reducing .contains() lookups from O(n) to O(1).

The problem

During script/module/function compilation, the bytecode compiler tracks declared function names, variable names, and parameter bindings using Vec<Sym>. These vectors are repeatedly checked with .contains() inside loops, creating O(n^2) behavior when a script has many declarations.

There are 22 .contains() calls in declarations.rs, many inside nested loops:

// O(n) outer loop x O(n) contains = O(n^2)
for declaration in var_declarations {
    for name in bound_names(&declaration) {
        if !declared_function_names.contains(&name) {  // O(n) per check
            if !declared_var_names.contains(&name) {   // O(n) per check
                declared_var_names.push(name);
            }
        }
    }
}

The fix

Replace Vec<Sym> with FxHashSet<Sym> for all name-tracking collections used only for membership checks. Where a collection is also iterated (e.g., declared_var_names for emitting bindings), a parallel FxHashSet is maintained alongside the Vec.

FxHashSet (from rustc_hash) is already used elsewhere in the codebase and provides faster hashing than std::collections::HashSet for small integer keys like Sym.

Affected functions

Function Collections converted
global_declaration_instantiation_context declared_function_names, declared_var_names
prepare_eval_declaration_instantiation declared_function_names, lexically_declared_names
global_declaration_instantiation declared_function_names, declared_var_names
eval_declaration_instantiation declared_function_names, declared_var_names
function_declaration_instantiation function_names, parameter_bindings, instantiated_var_names

Why this matters

Declaration instantiation runs on every script, eval, and function compilation. Real-world JavaScript bundles routinely have hundreds or thousands of declarations. The O(n^2) behavior is particularly visible when:

  • Loading large bundled scripts (webpack/rollup output with many top-level declarations)
  • Using eval() with significant code
  • Compiling functions with many local variables

Test plan

  • cargo check passes
  • cargo clippy -- no warnings
  • cargo test -p boa_engine --lib -- all 958 tests pass

Replace Vec with FxHashSet for name-tracking collections in bytecode
compiler declaration instantiation. 22 .contains() calls go from O(n)
to O(1), eliminating O(n^2) behavior when compiling scripts with many
declarations.

Affected: global/eval/function declaration instantiation functions.
@tkshsbcue
tkshsbcue requested a review from a team as a code owner March 13, 2026 04:35
@tkshsbcue

Copy link
Copy Markdown
Contributor Author

@jedel1043 i think you might fight this interesting haha!

@github-actions

Copy link
Copy Markdown

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 49,902 49,713 -189
Ignored 2,222 2,262 +40
Failed 839 988 +149
Panics 0 0 0
Conformance 94.22% 93.86% -0.36%
Fixed tests (2):
test/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-upper-b.js (previously Failed)
test/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-lower-b.js (previously Failed)
Broken tests (157):
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Lisu.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Garay.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Extender.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Changes_When_Casemapped.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/XID_Continue.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Tangut.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Kaithi.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Bengali.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Tai_Yo.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Decimal_Number.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Beria_Erfe.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Common.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Uppercase.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Cyrillic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Lowercase.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Elbasan.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Kawi.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Latin.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Old_Permic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Khitan_Small_Script.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Case_Ignorable.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Changes_When_NFKC_Casefolded.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Avestan.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Carian.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Changes_When_Titlecased.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Meroitic_Hieroglyphs.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Modifier_Letter.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Mongolian.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Common.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Kirat_Rai.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Sidetic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Gunjala_Gondi.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Myanmar.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Grapheme_Extend.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Tulu_Tigalari.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Extended_Pictographic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Cased_Letter.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Lowercase_Letter.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Other_Symbol.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Latin.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Gothic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Tolong_Siki.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Gurung_Khema.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Other_Letter.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Other.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Kawi.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Balinese.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Bopomofo.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/ID_Start.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Thai.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Symbol.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Myanmar.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Georgian.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Assigned.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Math.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Math_Symbol.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Glagolitic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Old_Turkic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Emoji_Presentation.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Samaritan.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Todhri.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Nonspacing_Mark.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Changes_When_Uppercased.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Ideographic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Sunuwar.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Cased.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Katakana.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Changes_When_Casefolded.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Tibetan.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Dash_Punctuation.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Cherokee.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Ethiopic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Beria_Erfe.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Changes_When_Lowercased.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Letter_Number.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Telugu.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Greek.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Adlam.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Han.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Mahajani.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Egyptian_Hieroglyphs.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Ol_Onal.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Lycian.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Tolong_Siki.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Sharada.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Emoji.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Tifinagh.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Garay.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Punctuation.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Lydian.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Phags_Pa.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Number.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Egyptian_Hieroglyphs.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Shavian.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Telugu.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/ID_Continue.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Runic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Tai_Yo.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Newa.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Kirat_Rai.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Han.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Bidi_Mirrored.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Other_Punctuation.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Arabic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Dash.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Kannada.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Ol_Onal.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Coptic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Kannada.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Todhri.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Nandinagari.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Alphabetic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Cyrillic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Sunuwar.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Syriac.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Diacritic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Sentence_Terminal.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Osage.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Gurung_Khema.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Tirhuta.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Tangut.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Old_Hungarian.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Tulu_Tigalari.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Sharada.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Terminal_Punctuation.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Inherited.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Khitan_Small_Script.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Grapheme_Base.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Unassigned.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Toto.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Armenian.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Tai_Le.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Devanagari.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Uppercase_Letter.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Arabic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/XID_Start.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Mark.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Duployan.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Letter.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Spacing_Mark.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Sidetic.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Hebrew.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Caucasian_Albanian.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Balinese.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/General_Category_-_Currency_Symbol.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Script_-_Inherited.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/Unified_Ideograph.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/strings/RGI_Emoji_Modifier_Sequence.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/strings/RGI_Emoji_Flag_Sequence.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/strings/Basic_Emoji.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/strings/RGI_Emoji.js (previously Passed)
test/built-ins/RegExp/property-escapes/generated/strings/RGI_Emoji_ZWJ_Sequence.js (previously Passed)
test/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-upper-w.js (previously Passed)
test/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-lower-w.js (previously Passed)
test/built-ins/Object/freeze/typedarray-backed-by-resizable-buffer.js (previously Passed)
test/staging/sm/RegExp/unicode-ignoreCase.js (previously Passed)
test/staging/sm/RegExp/unicode-ignoreCase-word-boundary.js (previously Passed)

Tested main commit: f36e2334f6a1b93b99ce218fb5d1ff8aa595383c
Tested PR commit: f37cb0679e5a74de36dbb0f17b335639631b9729
Compare commits: f36e233...f37cb06

@codecov

codecov Bot commented Mar 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.30435% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.50%. Comparing base (6ddc2b4) to head (89c0222).
⚠️ Report is 1031 commits behind head on main.

Files with missing lines Patch % Lines
core/engine/src/bytecompiler/declarations.rs 91.30% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5024       +/-   ##
===========================================
+ Coverage   47.24%   62.50%   +15.25%     
===========================================
  Files         476      534       +58     
  Lines       46892    59561    +12669     
===========================================
+ Hits        22154    37226    +15072     
+ Misses      24738    22335     -2403     

☔ View full report in Codecov by Harness.
📢 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.

@zhuzhu81998

Copy link
Copy Markdown
Contributor

do you have benchmark results? 👀 cargo bench -p boa_benches first on main and then on pr branch would be nice.

@tkshsbcue

Copy link
Copy Markdown
Contributor Author

hey hi @zhuzhu81998 these are the benchmarks i compiled

Benchmark main PR Change Significant?
strings/slice 1.030 ms 1.007 ms -2.3% Yes (improved)
v8/deltablue 5.052 µs 4.973 µs -1.4% Yes (improved)
v8/richards 5.018 µs 4.957 µs -1.5% Yes (improved)
v8/splay 5.019 µs 4.939 µs -1.5% Yes (improved)

@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

Copy link
Copy Markdown
Member

Need to fix formatting first

@github-actions

github-actions Bot commented Apr 6, 2026 •

Copy link
Copy Markdown

Test262 conformance changes

Test result main count PR count difference
Total 53,578 53,578 0
Passed 51,228 51,298 +70
Ignored 1,781 1,712 -69
Failed 569 568 -1
Panics 0 0 0
Conformance 95.61% 95.74% +0.13%
Fixed tests (70):
test/staging/sm/TypedArray/prototype-constructor-identity.js (previously Failed)
test/staging/Uint8Array/fromBase64/invalid-options.js (previously Ignored)
test/built-ins/Uint8Array/fromBase64/option-coercion.js (previously Ignored)
test/built-ins/Uint8Array/fromBase64/last-chunk-handling.js (previously Ignored)
test/built-ins/Uint8Array/fromBase64/ignores-receiver.js (previously Ignored)
test/built-ins/Uint8Array/fromBase64/descriptor.js (previously Ignored)
test/built-ins/Uint8Array/fromBase64/alphabet.js (previously Ignored)
test/built-ins/Uint8Array/fromBase64/string-coercion.js (previously Ignored)
test/built-ins/Uint8Array/fromBase64/whitespace.js (previously Ignored)
test/built-ins/Uint8Array/fromBase64/nonconstructor.js (previously Ignored)
test/built-ins/Uint8Array/fromBase64/name.js (previously Ignored)
test/built-ins/Uint8Array/fromBase64/last-chunk-invalid.js (previously Ignored)
test/built-ins/Uint8Array/fromBase64/length.js (previously Ignored)
test/built-ins/Uint8Array/fromBase64/results.js (previously Ignored)
test/built-ins/Uint8Array/fromBase64/illegal-characters.js (previously Ignored)
test/built-ins/Uint8Array/fromHex/ignores-receiver.js (previously Ignored)
test/built-ins/Uint8Array/fromHex/descriptor.js (previously Ignored)
test/built-ins/Uint8Array/fromHex/string-coercion.js (previously Ignored)
test/built-ins/Uint8Array/fromHex/odd-length-input.js (previously Ignored)
test/built-ins/Uint8Array/fromHex/nonconstructor.js (previously Ignored)
test/built-ins/Uint8Array/fromHex/name.js (previously Ignored)
test/built-ins/Uint8Array/fromHex/length.js (previously Ignored)
test/built-ins/Uint8Array/fromHex/results.js (previously Ignored)
test/built-ins/Uint8Array/fromHex/illegal-characters.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/option-coercion.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/last-chunk-handling.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/writes-up-to-error.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/descriptor.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/alphabet.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/string-coercion.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/whitespace.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/nonconstructor.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/target-size.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/name.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/detached-buffer.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/subarray.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/length.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/results.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/trailing-garbage.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/trailing-garbage-empty.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromBase64/illegal-characters.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromHex/throws-when-string-length-is-odd.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromHex/writes-up-to-error.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromHex/descriptor.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromHex/string-coercion.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromHex/nonconstructor.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromHex/target-size.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromHex/name.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromHex/detached-buffer.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromHex/subarray.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromHex/length.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromHex/results.js (previously Ignored)
test/built-ins/Uint8Array/prototype/setFromHex/illegal-characters.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toHex/descriptor.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toHex/nonconstructor.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toHex/name.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toHex/detached-buffer.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toHex/receiver-not-uint8array.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toHex/length.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toHex/results.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toBase64/option-coercion.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toBase64/descriptor.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toBase64/alphabet.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toBase64/nonconstructor.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toBase64/name.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toBase64/detached-buffer.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toBase64/receiver-not-uint8array.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toBase64/omit-padding.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toBase64/length.js (previously Ignored)
test/built-ins/Uint8Array/prototype/toBase64/results.js (previously Ignored)

Tested main commit: fe10d142a0bdd8653d74194378617e56c39e7a4a
Tested PR commit: 89c0222877488c5c7974d942846a83ed82b10e6b
Compare commits: fe10d14...89c0222

@tkshsbcue

Copy link
Copy Markdown
Contributor Author

hey @jedel1043 fixed formatting!

@zhuzhu81998

zhuzhu81998 commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

The names that are hashed here, they are not internal right? They come from JS?
So maybe FxHashSet is not ok here, since usecases of Boa probably include executing untrusted scripts (plugins etc.).

@tkshsbcue

Copy link
Copy Markdown
Contributor Author

hey @zhuzhu81998

The keys here are Sym, which is just a NonZeroUsize it's an integer index into the string interner, not the raw JS string itself. FxHash on sequential/near-sequential
integers is essentially a perfect hash with no realistic collision scenario. The actual JS name strings never reach the hasher.

@@ -718,6 +710,7 @@ impl ByteCompiler<'_> {

// 12. Let declaredVarNames be a new empty List.
let mut declared_var_names = Vec::new();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need this separately?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting we drop the Vec and use only the FxHashSet here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea unless there is a reason to keep this that i am not seeing? you dropped the Vec elsewhere already no?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could try to drop it, but IIRC the spec requires vars to be initialized in a certain order, so I don't know if using a hash set will break assumptions about this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, looking at it the iteration at step 18 just calls CreateGlobalVarBinding for each name, and those bindings are independent of each other. Wouldn't the end result be the same regardless of order?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhhh what should i do then lmao?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting we drop the Vec and use only the FxHashSet here?

This, but use a separate commit just in case it breaks tests. Makes reversing easier

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright i will implement this and push another follow up commit !

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @jedel1043 please have a look!

Remove the redundant Vec alongside the FxHashSet for
declared_var_names in global_declaration_instantiation and
eval_declaration_instantiation. The Vec was only iterated at the end,
and iteration order is not required by the spec for these bindings.
Comment on lines 259 to 264
// 2. Append fn to declaredFunctionNames.
if declared_function_names.insert(name.sym()) {
// SKIP: 1. If varEnv is a Global Environment Record, then

// 2. Append fn to declaredFunctionNames.
declared_function_names.push(name.sym());

// SKIP: 3. Insert d as the first element of functionsToInitialize.
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need this empty if block?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha Good catch after the Vec→FxHashSet swap the body is just // SKIP: spec-comment markers, so the if wraps nothing. I'll drop it (same applies to the matching blocks at lines 93, 422, 668, and 944) and keep just declared_function_names.insert(name.sym());.

if !strict {
let lexically_declared_names = lexically_declared_names(body);
let lexically_declared_names: FxHashSet<Sym> =
lexically_declared_names(body).into_iter().collect();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the doc of lexically_declared_names says:

/// Returns a list with the lexical bindings of a node, which may contain duplicates.
///
/// This is equivalent to the [`LexicallyDeclaredNames`][spec] syntax operation in the spec.
///
/// [spec]: https://tc39.es/ecma262/#sec-static-semantics-lexicallydeclarednames

what cases will result in duplicates here? 🤔

@tkshsbcue tkshsbcue Apr 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicates can occur in the !strict branch via Annex B e.g. sibling blocks each declaring the same function name, or repeated function bindings across nested CaseClauses. That said, dedup isn't really the goal of the change here; the loop below does .contains(&f) for every Annex B function name, so the win is O(1) lookup vs O(n) scan. I'll update the commit message / PR description to make that the stated motivation rather than "duplicates"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my concern is whether or not the preservation of duplicates is necessary here for correctness/spec-compliance

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No dedup is safe here. The only use of lexically_declared_names in this block is the .contains(&f) membership check in the Annex B loop below:

  for f in annex_b_function_declarations_names(body) {                                                                                                                       
      if !lexically_declared_names.contains(&f) {                                                                                                                            
          ...                                                                                                                                                                
      }                                                                                                                                                                      
  }   

Addresses review feedback: after the container swap, two sites had the
shape `if set.insert(x) { /* only SKIP comments */ }`, where the boolean
return of insert was no longer meaningful. Collapse those to a plain
`set.insert(x);` and move the SKIP spec-step comments above the call to
preserve the spec-structure reading order.

@zhuzhu81998 zhuzhu81998 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than linting it looks fine.
The failed test262 tests seem unrelated.

but ig the maintainers are busy with reviewing proposals right now XD

@tkshsbcue

Copy link
Copy Markdown
Contributor Author

@jedel1043 i hope you can review this one!

@jedel1043 jedel1043 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice optimization!

@jedel1043
jedel1043 enabled auto-merge August 30, 2026 18:29
@jedel1043
jedel1043 added this pull request to the merge queue Aug 30, 2026
Merged via the queue into boa-dev:main with commit 0241300 Aug 30, 2026
22 checks passed
@jedel1043 jedel1043 modified the milestones: v0.23.0, v0.22 Aug 30, 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 Author Waiting on PR changes from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants