optimize:performance code

This commit is contained in:
pengfei.zhou 2021-07-08 10:57:08 +08:00 committed by osborn
parent a40413f991
commit 34876de69f
2 changed files with 15 additions and 7 deletions

View File

@ -141,17 +141,25 @@ public class DoricNativeDriver implements IDoricDriver {
}
}
private DoricPerformanceProfile getDoricPerformanceProfile(String contextId) {
DoricContext doricContext = DoricContextManager.getContext(contextId);
if (doricContext != null) {
return doricContext.getPerformanceProfile();
}
return new DoricPerformanceProfile("Empty");
}
@Override
public AsyncResult<Boolean> createContext(final String contextId, final String script, final String source) {
final DoricPerformanceProfile performanceProfile = DoricContextManager.getContext(contextId).getPerformanceProfile();
performanceProfile.prepare(DoricPerformanceProfile.STEP_CREATE);
final DoricPerformanceProfile profile = getDoricPerformanceProfile(contextId);
profile.prepare(DoricPerformanceProfile.STEP_CREATE);
return AsyncCall.ensureRunInHandler(mJSHandler, new Callable<Boolean>() {
@Override
public Boolean call() {
try {
performanceProfile.start(DoricPerformanceProfile.STEP_CREATE);
profile.start(DoricPerformanceProfile.STEP_CREATE);
doricJSEngine.prepareContext(contextId, script, source);
performanceProfile.end(DoricPerformanceProfile.STEP_CREATE);
profile.end(DoricPerformanceProfile.STEP_CREATE);
return true;
} catch (Exception e) {
doricJSEngine.getRegistry().onException(DoricContextManager.getContext(contextId), e);
@ -164,7 +172,7 @@ public class DoricNativeDriver implements IDoricDriver {
@Override
public AsyncResult<Boolean> destroyContext(final String contextId) {
final DoricPerformanceProfile profile = DoricContextManager.getContext(contextId).getPerformanceProfile();
final DoricPerformanceProfile profile = getDoricPerformanceProfile(contextId);
profile.prepare(DoricPerformanceProfile.STEP_DESTROY);
return AsyncCall.ensureRunInHandler(mJSHandler, new Callable<Boolean>() {
@Override

View File

@ -97,7 +97,7 @@ - (instancetype)init {
}.mutableCopy;
self.registry = [[DoricRegistry alloc] initWithJSEngine:self];
[self ensureRunOnJSThread:^() {
[_profile start:@"Init"];
[self.profile start:@"Init"];
self.timers = [[NSMutableDictionary alloc] init];
self.bridgeExtension = [DoricBridgeExtension new];
self.bridgeExtension.registry = self.registry;
@ -105,7 +105,7 @@ - (instancetype)init {
[self initJSExecutor];
[self initDoricEnvironment];
self.initialized = YES;
[_profile end:@"Init"];
[self.profile end:@"Init"];
}];
[self.registry registerMonitor:[DoricDefaultMonitor new]];
}