Skip to content

Commit f169b57

Browse files
mkustermanncommit-bot@chromium.org
authored andcommitted
[vm] Avoid eager creation of patch classes array in kernel loader
This reduces g3 customer's AOT compilation with gen_snapshot from around 8 GB to 1 GB Issue #42549 Issue b/161980815 Change-Id: Ic68248458ecb1c5d7b9a1e7e2296a88ebb910b19 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155610 Reviewed-by: Daco Harkes <[email protected]> Commit-Queue: Martin Kustermann <[email protected]>
1 parent c65b444 commit f169b57

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

runtime/vm/kernel_loader.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ void KernelLoader::InitializeFields(UriToSourceTable* uri_to_source_table) {
376376
const intptr_t source_table_size = helper_.SourceTableSize();
377377
const Array& scripts =
378378
Array::Handle(Z, Array::New(source_table_size, Heap::kOld));
379-
patch_classes_ = Array::New(source_table_size, Heap::kOld);
380379

381380
// Copy the Kernel string offsets out of the binary and into the VM's heap.
382381
ASSERT(program_->string_table_offset() >= 0);
@@ -489,11 +488,7 @@ KernelLoader::KernelLoader(const Script& script,
489488
expression_evaluation_library_(Library::Handle(Z)) {
490489
ASSERT(T.active_class_ == &active_class_);
491490
T.finalize_ = false;
492-
493-
const Array& scripts = Array::Handle(Z, kernel_program_info_.scripts());
494-
patch_classes_ = Array::New(scripts.Length(), Heap::kOld);
495491
library_kernel_data_ = kernel_data.raw();
496-
497492
H.InitFromKernelProgramInfo(kernel_program_info_);
498493
}
499494

@@ -2107,6 +2102,13 @@ const Object& KernelLoader::ClassForScriptAt(const Class& klass,
21072102
intptr_t source_uri_index) {
21082103
const Script& correct_script = Script::Handle(Z, ScriptAt(source_uri_index));
21092104
if (klass.script() != correct_script.raw()) {
2105+
// Lazily create the [patch_classes_] array in case we need it.
2106+
if (patch_classes_.IsNull()) {
2107+
const Array& scripts = Array::Handle(Z, kernel_program_info_.scripts());
2108+
ASSERT(!scripts.IsNull());
2109+
patch_classes_ = Array::New(scripts.Length(), Heap::kOld);
2110+
}
2111+
21102112
// Use cache for patch classes. This works best for in-order usages.
21112113
PatchClass& patch_class = PatchClass::ZoneHandle(Z);
21122114
patch_class ^= patch_classes_.At(source_uri_index);

0 commit comments

Comments
 (0)