Skip to content

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

Open
tkshsbcue wants to merge 4 commits intoboa-dev:mainfrom
tkshsbcue:perf/hashset-declaration-lookups
Open

perf: use FxHashSet for O(1) name lookups in declaration instantiation#5024
tkshsbcue wants to merge 4 commits intoboa-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
Copy link
Copy Markdown

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.76%. Comparing base (6ddc2b4) to head (fd75f4a).
⚠️ Report is 944 commits behind head on main.

Files with missing lines Patch % Lines
core/engine/src/bytecompiler/declarations.rs 92.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5024       +/-   ##
===========================================
+ Coverage   47.24%   59.76%   +12.51%     
===========================================
  Files         476      589      +113     
  Lines       46892    63632    +16740     
===========================================
+ Hits        22154    38027    +15873     
- Misses      24738    25605      +867     

☔ 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.

@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
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

Test262 conformance changes

Test result main count PR count difference
Total 53,125 53,125 0
Passed 51,049 51,049 0
Ignored 1,482 1,482 0
Failed 594 594 0
Panics 0 0 0
Conformance 96.09% 96.09% 0.00%

Tested main commit: b895f7411e6a74206c1bec8ba5a02df6791d12a2
Tested PR commit: fd75f4a5cc6870444af7c126f77cf7b78fd273f9
Compare commits: b895f74...fd75f4a

@tkshsbcue
Copy link
Copy Markdown
Contributor Author

hey @jedel1043 fixed formatting!

@zhuzhu81998
Copy link
Copy Markdown
Contributor

zhuzhu81998 commented Apr 7, 2026

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.
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