* Reduce emit overhead to ~50% of prior, by caching class-name of java-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 https://github.com/facebook/react-native/pull/11118

Reviewed By: astreet

Differential Revision: D4232794

Pulled By: javache

fbshipit-source-id: 25ca1cfc170a343e71ff8915c3fa7e38884a402b
This commit is contained in:
Venryx 2016-11-29 02:43:49 -08:00 committed by Facebook Github Bot
parent 30152ff5b4
commit c4046d62a7
1 changed files with 16 additions and 9 deletions

View File

@ -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 @@ import com.facebook.react.common.build.ReactBuildConfig;
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 class JavaScriptModuleRegistration {
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() {