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

Unified Diff: sdk/lib/_internal/js_runtime/lib/interceptors.dart

Issue 2332953002: Cache constructors of UnknownJavaScriptObject objects in side-map (Closed)
Patch Set: rebased Created 4 years, 3 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 | « no previous file | sdk/lib/_internal/js_runtime/lib/native_helper.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/js_runtime/lib/interceptors.dart
diff --git a/sdk/lib/_internal/js_runtime/lib/interceptors.dart b/sdk/lib/_internal/js_runtime/lib/interceptors.dart
index 23025ad578cc34276949080428a92a0e7b49fcab..516c43f90bd6d8b40bde15e3377922a321a57064 100644
--- a/sdk/lib/_internal/js_runtime/lib/interceptors.dart
+++ b/sdk/lib/_internal/js_runtime/lib/interceptors.dart
@@ -168,7 +168,16 @@ getNativeInterceptor(object) {
}
}
- var interceptor = lookupAndCacheInterceptor(object);
+ // Check for cached UnknownJavaScriptObject. This avoids doing the slow
+ // dispatch-record based lookup for repeated js-interop classes.
+ var constructor = JS('', '#.constructor', object);
+ var interceptor = JS('', '#.get(#)', constructorToInterceptor, constructor);
+ if (interceptor != null) return interceptor;
+
+ // This takes care of dispatch-record based caching, but not constructor based
+ // caching of [UnknownJavaScriptObject]s.
+ interceptor = lookupAndCacheInterceptor(object);
+
if (interceptor == null) {
// JavaScript Objects created via object literals and `Object.create(null)`
// are 'plain' Objects. This test could be simplified and the dispatch path
@@ -181,13 +190,18 @@ getNativeInterceptor(object) {
if (JS('bool', '# == null || # === Object.prototype', proto, proto)) {
return JS_INTERCEPTOR_CONSTANT(PlainJavaScriptObject);
} else {
- return JS_INTERCEPTOR_CONSTANT(UnknownJavaScriptObject);
+ interceptor = JS_INTERCEPTOR_CONSTANT(UnknownJavaScriptObject);
+ JS('', '#.set(#, #)', constructorToInterceptor, constructor, interceptor);
+ return interceptor;
}
}
return interceptor;
}
+var constructorToInterceptor =
+ JS('', 'typeof(self.WeakMap) == "undefined" ? new Map() : new WeakMap()');
+
/**
* Data structure used to map a [Type] to the [Interceptor] and constructors for
* that type. It is JavaScript array of 3N entries of adjacent slots containing
« no previous file with comments | « no previous file | sdk/lib/_internal/js_runtime/lib/native_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698