Commit 12c79495 authored by Marja Hölttä's avatar Marja Hölttä Committed by V8 LUCI CQ

[web snapshot] Perf fix: pre-reserve the space in the global object

Exports are properties in the global object. Pre-reserve the space,
since we know the count upfront.

Bug: v8:11525
Change-Id: Ia8ea992234ed8cf71a1060254766b0ba31562436
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3416231Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78767}
parent 3f9f569c
...@@ -1754,6 +1754,16 @@ void WebSnapshotDeserializer::DeserializeExports() { ...@@ -1754,6 +1754,16 @@ void WebSnapshotDeserializer::DeserializeExports() {
Throw("Malformed export table"); Throw("Malformed export table");
return; return;
} }
// Pre-reserve the space for the properties we're going to add to the global
// object.
Handle<JSGlobalObject> global = isolate_->global_object();
Handle<GlobalDictionary> dictionary(
global->global_dictionary(isolate_, kAcquireLoad), isolate_);
dictionary = GlobalDictionary::EnsureCapacity(isolate_, dictionary, count,
AllocationType::kYoung);
global->set_global_dictionary(*dictionary, kReleaseStore);
for (uint32_t i = 0; i < count; ++i) { for (uint32_t i = 0; i < count; ++i) {
Handle<String> export_name = ReadString(true); Handle<String> export_name = ReadString(true);
Handle<Object> export_value; Handle<Object> export_value;
...@@ -1770,8 +1780,8 @@ void WebSnapshotDeserializer::DeserializeExports() { ...@@ -1770,8 +1780,8 @@ void WebSnapshotDeserializer::DeserializeExports() {
return; return;
} }
auto result = Object::SetProperty(isolate_, isolate_->global_object(), auto result =
export_name, export_value); Object::SetProperty(isolate_, global, export_name, export_value);
if (result.is_null()) { if (result.is_null()) {
Throw("Setting global property failed"); Throw("Setting global property failed");
return; return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment