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 @Override
public AsyncResult<Boolean> createContext(final String contextId, final String script, final String source) { public AsyncResult<Boolean> createContext(final String contextId, final String script, final String source) {
final DoricPerformanceProfile performanceProfile = DoricContextManager.getContext(contextId).getPerformanceProfile(); final DoricPerformanceProfile profile = getDoricPerformanceProfile(contextId);
performanceProfile.prepare(DoricPerformanceProfile.STEP_CREATE); profile.prepare(DoricPerformanceProfile.STEP_CREATE);
return AsyncCall.ensureRunInHandler(mJSHandler, new Callable<Boolean>() { return AsyncCall.ensureRunInHandler(mJSHandler, new Callable<Boolean>() {
@Override @Override
public Boolean call() { public Boolean call() {
try { try {
performanceProfile.start(DoricPerformanceProfile.STEP_CREATE); profile.start(DoricPerformanceProfile.STEP_CREATE);
doricJSEngine.prepareContext(contextId, script, source); doricJSEngine.prepareContext(contextId, script, source);
performanceProfile.end(DoricPerformanceProfile.STEP_CREATE); profile.end(DoricPerformanceProfile.STEP_CREATE);
return true; return true;
} catch (Exception e) { } catch (Exception e) {
doricJSEngine.getRegistry().onException(DoricContextManager.getContext(contextId), e); doricJSEngine.getRegistry().onException(DoricContextManager.getContext(contextId), e);
@ -164,7 +172,7 @@ public class DoricNativeDriver implements IDoricDriver {
@Override @Override
public AsyncResult<Boolean> destroyContext(final String contextId) { public AsyncResult<Boolean> destroyContext(final String contextId) {
final DoricPerformanceProfile profile = DoricContextManager.getContext(contextId).getPerformanceProfile(); final DoricPerformanceProfile profile = getDoricPerformanceProfile(contextId);
profile.prepare(DoricPerformanceProfile.STEP_DESTROY); profile.prepare(DoricPerformanceProfile.STEP_DESTROY);
return AsyncCall.ensureRunInHandler(mJSHandler, new Callable<Boolean>() { return AsyncCall.ensureRunInHandler(mJSHandler, new Callable<Boolean>() {
@Override @Override

View File

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