Skip to content

Quadratic behavior in kernel loading #42549

@mkustermann

Description

@mkustermann

The VM finalizes classes lazily when it needs them. When it decides to finalize a class it will call into the kernel loader to load all fields/functions/... of the (possibly top-level) class.

See runtime/vm/kernel_loader.cc:KernelLoader::FinishClassLoading:

void KernelLoader::FinishLoading(const Class& klass) {
  ...
  KernelLoader kernel_loader(...);
  ...

This constructor will execute the code in runtime/vm/kernel_loader.cc:KernelLoader::KernelLoader:

KernelLoader::KernelLoader(...) {
  ...
  const Array& scripts = Array::Handle(Z, kernel_program_info_.scripts());
  patch_classes_ = Array::New(scripts.Length(), Heap::kOld);
  ...
}

Now very often the entire application is represented as one KernelProgramInfo object.
The number of classes is always larger than the number of scripts / library since each script has it's own top-level class.

=> The complexity is O(#number-classes x #number-of-scripts)
=> For large number of libraries this can be very slow (finalization of each class can cause ~ 1MB allocation, causing very frequent GCs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions