Permalink
Browse files

* Reduce emit overhead to ~50% of prior, by caching class-name of jav…

…a-script module/interface.

Summary:
Made modification to react-native code that reduces the communication channel overhead to ~50% of prior, in some cases, by caching the class-name of the java-script module/interface.

For me it reduced the run-time of the RCTDeviceEventEmitter.emit function from 1438ms to 715ms, over a period of 8 seconds in my Android app. My project requires many emit calls, as I'm transferring real-time EEG data from a Muse headband to my react-native UI to be graphed, so this optimization was very helpful in my case.
Closes #11118

Reviewed By: astreet

Differential Revision: D4232794

Pulled By: javache

fbshipit-source-id: 25ca1cfc170a343e71ff8915c3fa7e38884a402b
  • Loading branch information...
1 parent 30152ff commit c4046d62a7cff03ce03f2099075eb083ade09c23 @Venryx Venryx committed with Facebook Github Bot Nov 29, 2016
@@ -10,6 +10,7 @@
package com.facebook.react.bridge;
import javax.annotation.concurrent.Immutable;
+import javax.annotation.Nullable;
import java.lang.reflect.Method;
import java.util.Arrays;
@@ -26,6 +27,7 @@
public class JavaScriptModuleRegistration {
private final Class<? extends JavaScriptModule> mModuleInterface;
+ private @Nullable String mName;
public JavaScriptModuleRegistration(Class<? extends JavaScriptModule> moduleInterface) {
mModuleInterface = moduleInterface;
@@ -45,17 +47,22 @@ public JavaScriptModuleRegistration(Class<? extends JavaScriptModule> moduleInte
public Class<? extends JavaScriptModule> getModuleInterface() {
return mModuleInterface;
}
-
+
public String getName() {
- // With proguard obfuscation turned on, proguard apparently (poorly) emulates inner classes or
- // something because Class#getSimpleName() no longer strips the outer class name. We manually
- // strip it here if necessary.
- String name = mModuleInterface.getSimpleName();
- int dollarSignIndex = name.lastIndexOf('$');
- if (dollarSignIndex != -1) {
- name = name.substring(dollarSignIndex + 1);
+ if (mName == null) {
+ // With proguard obfuscation turned on, proguard apparently (poorly) emulates inner classes or
+ // something because Class#getSimpleName() no longer strips the outer class name. We manually
+ // strip it here if necessary.
+ String name = mModuleInterface.getSimpleName();
+ int dollarSignIndex = name.lastIndexOf('$');
+ if (dollarSignIndex != -1) {
+ name = name.substring(dollarSignIndex + 1);
+ }
+
+ // getting the class name every call is expensive, so cache it
+ mName = name;
}
- return name;
+ return mName;
}
public List<Method> getMethods() {

0 comments on commit c4046d6

Please sign in to comment.