Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Unified Diff: runtime/vm/kernel_reader.cc

Issue 2967593002: [kernel] Cache patch-classes. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/kernel_reader.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/kernel_reader.cc
diff --git a/runtime/vm/kernel_reader.cc b/runtime/vm/kernel_reader.cc
index dbf4eabe1783168d0263ec0f6d0ee6934642d64c..2352c362764850d74398bf8b9b9a880a45aa1540 100644
--- a/runtime/vm/kernel_reader.cc
+++ b/runtime/vm/kernel_reader.cc
@@ -126,6 +126,7 @@ KernelReader::KernelReader(Program* program)
zone_(thread_->zone()),
isolate_(thread_->isolate()),
scripts_(Array::ZoneHandle(zone_)),
+ patch_classes_(Array::ZoneHandle(zone_)),
translation_helper_(this, thread_),
builder_(&translation_helper_,
zone_,
@@ -135,6 +136,7 @@ KernelReader::KernelReader(Program* program)
T.finalize_ = false;
scripts_ = Array::New(builder_.SourceTableSize(), Heap::kOld);
+ patch_classes_ = Array::New(builder_.SourceTableSize(), Heap::kOld);
// Copy the Kernel string offsets out of the binary and into the VM's heap.
ASSERT(program->string_table_offset() >= 0);
@@ -680,9 +682,14 @@ const Object& KernelReader::ClassForScriptAt(const dart::Class& klass,
intptr_t source_uri_index) {
Script& correct_script = ScriptAt(source_uri_index);
if (klass.script() != correct_script.raw()) {
- // TODO(jensj): We could probably cache this so we don't create
- // new PatchClasses all the time
- return PatchClass::ZoneHandle(Z, PatchClass::New(klass, correct_script));
+ // Use cache for patch classes. This works best for in-order usages.
+ PatchClass& patch_class = PatchClass::ZoneHandle(Z);
+ patch_class ^= patch_classes_.At(source_uri_index);
+ if (patch_class.IsNull() || patch_class.origin_class() != klass.raw()) {
+ patch_class = PatchClass::New(klass, correct_script);
+ patch_classes_.SetAt(source_uri_index, patch_class);
+ }
+ return patch_class;
}
return klass;
}
« no previous file with comments | « runtime/vm/kernel_reader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698