Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

[WEEX-281][android] Auto Startup Time Quick #1141

Merged
merged 3 commits into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public class WXEnvironment {
/** from init to sdk-ready **/
public static long sSDKInitTime =0;

/**
* component and modules ready
* */
public static long sComponentsAndModulesReadyTime = 0;

public static LogLevel sLogLevel = LogLevel.DEBUG;
private static boolean isApkDebug = true;
public static boolean isPerf = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,7 @@ private void initFramework(String framework) {
execRegisterFailTask();
WXEnvironment.JsFrameworkInit = true;
registerDomModule();
trackComponentAndModulesTime();
String reinitInfo = "";
if (reInitCount > 1) {
reinitInfo = "reinit Framework:";
Expand Down Expand Up @@ -1709,6 +1710,17 @@ private void initFramework(String framework) {
}
}

private void trackComponentAndModulesTime() {
post(new Runnable() {
@Override
public void run() {
WXEnvironment.sComponentsAndModulesReadyTime = System.currentTimeMillis() - WXEnvironment.sSDKInitStart;
WXLogUtils.renderPerformanceLog("ComponentModulesReadyTime", WXEnvironment.sComponentsAndModulesReadyTime);
WXLogUtils.d("ComponentModulesReadyTime " + WXEnvironment.sComponentsAndModulesReadyTime);
}
});
}

@SuppressWarnings("unchecked")
private void invokeCallJSBatch(Message message) {
if (mNextTickTasks.isEmpty() || !isJSFrameworkInit()) {
Expand Down Expand Up @@ -1844,12 +1856,18 @@ public void registerComponents(final List<Map<String, Object>> components) {
|| components.size() == 0) {
return;
}
post(new Runnable() {
Runnable runnable = new Runnable() {
@Override
public void run() {
invokeRegisterComponents(components, mRegisterComponentFailList);
}
}, null);
};

if(isJSThread() && isJSFrameworkInit()){
runnable.run();
}else{
post(runnable, null);
}
}

public void execJSService(final String service) {
Expand Down Expand Up @@ -1910,9 +1928,9 @@ private void invokeRegisterModules(Map<String, Object> modules, List<Map<String,
WXModuleManager.resetModuleState(module, true);
WXLogUtils.e("[WXBridgeManager]invokeRegisterModules METHOD_REGISTER_MODULES success module:" + module);
}

}
} catch (Throwable e) {
WXLogUtils.e("Weex [invokeRegisterModules]", e);
}
} catch (Throwable e) {
WXExceptionUtils.commitCriticalExceptionRT(null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Invoker getMethodInvoker(String name) {
}

@Override
public String[] getMethods() {
public synchronized String[] getMethods() {
if(mMethodInvokers == null && !generate()){
//generate failed
return new String[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public Invoker getMethodInvoker(String name) {
}

@Override
public String[] getMethods() {
public synchronized String[] getMethods() {
if(mMethodInvokers == null){
generate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.bridge.WXBridgeManager;
import com.taobao.weex.common.WXException;
import com.taobao.weex.ui.config.AutoScanConfigRegister;
import com.taobao.weex.utils.WXLogUtils;

import java.util.ArrayList;
Expand All @@ -45,6 +46,9 @@ public static synchronized boolean registerComponent(final String type, final IF
return false;
}

//register component
AutoScanConfigRegister.preLoad(holder);

//execute task in js thread to make sure register order is same as the order invoke register method.
WXBridgeManager.getInstance()
.post(new Runnable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
import com.alibaba.fastjson.JSONObject;
import com.taobao.weex.WXEnvironment;
import com.taobao.weex.WXSDKEngine;
import com.taobao.weex.bridge.JavascriptInvokable;
import com.taobao.weex.utils.WXFileUtils;
import com.taobao.weex.utils.WXLogUtils;

import java.io.IOException;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
* Created by furture on 2018/2/7.
Expand All @@ -40,6 +42,20 @@ public class AutoScanConfigRegister {

public static final String TAG = "WeexScanConfigRegister";

private static ConcurrentLinkedQueue<JavascriptInvokable> autoLoadClass = new ConcurrentLinkedQueue<>();

/**
* pre load module class and methods when so&jsf init
**/
public static void preLoad(JavascriptInvokable invokable){
if(invokable instanceof ConfigModuleFactory){
return;
}
if(invokable instanceof ConfigComponentHolder){
return;
}
autoLoadClass.add(invokable);
}

/**
* auto scan config files and do auto config from files, none need center register
Expand All @@ -49,6 +65,16 @@ public static void doScanConfig(){
@Override
public void run() {
doScanConfigSync();
JavascriptInvokable invokable = autoLoadClass.poll();
int count = 0;
while (invokable != null){
invokable.getMethods();
invokable = autoLoadClass.poll();
count++;
}
if(WXEnvironment.isApkDebugable()){
WXLogUtils.d(TAG, "auto preload class's methods count " + count);
}
}
});
thread.setName("AutoScanConfigRegister");
Expand Down