Commit ab3be5a1 authored by mnaganov@chromium.org's avatar mnaganov@chromium.org

[Android] Cache injected Java objects' methods info on renderer side

Every invocation of Java method via an interface JS wrapper injected by Java bridge
is preceded by a call to GetNamedProperty. As method presence can't change
during Java object's lifetime, we should cache it on the renderer side, as every
IPC call to the browser side is super-expensive.

This optimization improves Cordova's "exec" benchmark speed by astonishing 60%, as
we shave off half of the IPC calls.

BUG=355644

Review URL: https://codereview.chromium.org/381683002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282345 0039d316-1c4b-4281-b951-d872f2087c98
parent a9471a7d
...@@ -83,7 +83,15 @@ gin::ObjectTemplateBuilder GinJavaBridgeObject::GetObjectTemplateBuilder( ...@@ -83,7 +83,15 @@ gin::ObjectTemplateBuilder GinJavaBridgeObject::GetObjectTemplateBuilder(
v8::Local<v8::Value> GinJavaBridgeObject::GetNamedProperty( v8::Local<v8::Value> GinJavaBridgeObject::GetNamedProperty(
v8::Isolate* isolate, v8::Isolate* isolate,
const std::string& property) { const std::string& property) {
if (dispatcher_ && dispatcher_->HasJavaMethod(object_id_, property)) { std::map<std::string, bool>::iterator method_pos =
known_methods_.find(property);
if (method_pos == known_methods_.end()) {
if (!dispatcher_) {
return v8::Local<v8::Value>();
}
known_methods_[property] = dispatcher_->HasJavaMethod(object_id_, property);
}
if (known_methods_[property]) {
return gin::CreateFunctionTemplate( return gin::CreateFunctionTemplate(
isolate, isolate,
base::Bind(&GinJavaBridgeObject::InvokeMethod, base::Bind(&GinJavaBridgeObject::InvokeMethod,
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef CONTENT_RENDERER_JAVA_GIN_JAVA_BRIDGE_OBJECT_H_ #ifndef CONTENT_RENDERER_JAVA_GIN_JAVA_BRIDGE_OBJECT_H_
#define CONTENT_RENDERER_JAVA_GIN_JAVA_BRIDGE_OBJECT_H_ #define CONTENT_RENDERER_JAVA_GIN_JAVA_BRIDGE_OBJECT_H_
#include <set> #include <map>
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
...@@ -61,6 +61,7 @@ class GinJavaBridgeObject : public gin::Wrappable<GinJavaBridgeObject>, ...@@ -61,6 +61,7 @@ class GinJavaBridgeObject : public gin::Wrappable<GinJavaBridgeObject>,
base::WeakPtr<GinJavaBridgeDispatcher> dispatcher_; base::WeakPtr<GinJavaBridgeDispatcher> dispatcher_;
GinJavaBridgeDispatcher::ObjectID object_id_; GinJavaBridgeDispatcher::ObjectID object_id_;
scoped_ptr<GinJavaBridgeValueConverter> converter_; scoped_ptr<GinJavaBridgeValueConverter> converter_;
std::map<std::string, bool> known_methods_;
DISALLOW_COPY_AND_ASSIGN(GinJavaBridgeObject); DISALLOW_COPY_AND_ASSIGN(GinJavaBridgeObject);
}; };
......
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