1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

LibJS: Use Vector instead of HashMap in DeclarativeEnvironment

Constructing the HashMap in DeclarativeEnvironment was by far the most
expensive thing when making JavaScript function calls.

As it turns out, we don't really need this to be a HashMap in the first
place, as lookups are cached (by EnvironmentCoordinate) after the first
access, so after that we were not even looking in the HashMap, going
directly to the bindings Vector instead.

This reduces function_declaration_instantiation() from 16% to 9% when
idling in "Biolab Disaster". It also reduces has_binding() from 3% to
1% on the same content.

With these changes, we now actually get to idle a little bit between
game frames on my machine. :^)
This commit is contained in:
Andreas Kling 2022-03-07 14:02:37 +01:00
parent 2dad3dca9a
commit ff60e8ffc6
3 changed files with 30 additions and 50 deletions

View file

@ -1612,7 +1612,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto const& variable = interpreter->global_object();
list_all_properties(variable.shape(), variable_name);
for (String& name : global_environment.declarative_record().bindings()) {
for (auto const& name : global_environment.declarative_record().bindings()) {
if (name.starts_with(variable_name)) {
results.empend(name);
results.last().invariant_offset = variable_name.length();