@lynx-js/web-worker-runtime 0.9.1 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/dist/backgroundThread/background-apis/createNapiLoader.js +4 -2
- package/dist/backgroundThread/background-apis/createNativeApp.d.ts +2 -1
- package/dist/backgroundThread/background-apis/createNativeApp.js +7 -8
- package/dist/backgroundThread/background-apis/createNativeModules.d.ts +1 -1
- package/dist/backgroundThread/background-apis/createNativeModules.js +4 -4
- package/dist/backgroundThread/background-apis/createPerformanceApis.d.ts +2 -4
- package/dist/backgroundThread/background-apis/createPerformanceApis.js +6 -10
- package/dist/backgroundThread/background-apis/createTimingSystem.d.ts +8 -0
- package/dist/backgroundThread/background-apis/createTimingSystem.js +84 -0
- package/dist/backgroundThread/background-apis/startBackgroundThread.js +5 -5
- package/dist/mainThread/crossThreadHandlers/createMainthreadMarkTimingInternal.js +2 -2
- package/dist/mainThread/startMainThread.js +34 -7
- package/package.json +5 -4
- package/dist/backgroundThread/background-apis/crossThreadHandlers/createBackgroundMarkTimingInternal.d.ts +0 -2
- package/dist/backgroundThread/background-apis/crossThreadHandlers/createBackgroundMarkTimingInternal.js +0 -14
- package/dist/backgroundThread/background-apis/crossThreadHandlers/registerPostTimingResultHandler.d.ts +0 -3
- package/dist/backgroundThread/background-apis/crossThreadHandlers/registerPostTimingResultHandler.js +0 -46
- package/dist/mainThread/crossThreadHandlers/registerPostMainThreadEventHandler.d.ts +0 -2
- package/dist/mainThread/crossThreadHandlers/registerPostMainThreadEventHandler.js +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @lynx-js/web-worker-runtime
|
|
2
2
|
|
|
3
|
+
## 0.10.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat: onNapiModulesCall function add new param: `dispatchNapiModules`, napiModulesMap val add new param: `handleDispatch`. ([#414](https://github.com/lynx-family/lynx-stack/pull/414))
|
|
8
|
+
|
|
9
|
+
Now you can use them to actively communicate to napiModules (background thread) in onNapiModulesCall (ui thread).
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`1af3b60`](https://github.com/lynx-family/lynx-stack/commit/1af3b6052ab27f98bf0e4d1b0ec9f7d9e88e0afc)]:
|
|
12
|
+
- @lynx-js/web-constants@0.10.1
|
|
13
|
+
- @lynx-js/web-mainthread-apis@0.10.1
|
|
14
|
+
- @lynx-js/web-worker-rpc@0.10.1
|
|
15
|
+
|
|
16
|
+
## 0.10.0
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- feat: rewrite the main thread Element PAPIs ([#343](https://github.com/lynx-family/lynx-stack/pull/343))
|
|
21
|
+
|
|
22
|
+
In this commit we've rewritten the main thread apis.
|
|
23
|
+
|
|
24
|
+
The most highlighted change is that
|
|
25
|
+
|
|
26
|
+
- Before this commit we send events directly to bts
|
|
27
|
+
- After this change, we send events to mts then send them to bts with some data combined.
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- Updated dependencies [[`2a8ddf3`](https://github.com/lynx-family/lynx-stack/commit/2a8ddf3fb2a2fc5ed9b44184e30847aaf74fd1f4), [`3a8dabd`](https://github.com/lynx-family/lynx-stack/commit/3a8dabd877084c15db1404c912dd8a19c7a0fc59), [`878050a`](https://github.com/lynx-family/lynx-stack/commit/878050aaa3d9eb534848cab1dd0d4a2096a0a940), [`a521759`](https://github.com/lynx-family/lynx-stack/commit/a5217592f5aebea4b17860e729d523ecabb5f691), [`890c6c5`](https://github.com/lynx-family/lynx-stack/commit/890c6c51470c82104abb1049681f55e5d97cf9d6)]:
|
|
32
|
+
- @lynx-js/web-mainthread-apis@0.10.0
|
|
33
|
+
- @lynx-js/web-constants@0.10.0
|
|
34
|
+
- @lynx-js/web-worker-rpc@0.10.0
|
|
35
|
+
|
|
3
36
|
## 0.9.1
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { napiModulesCallEndpoint, } from '@lynx-js/web-constants';
|
|
4
|
+
import { dispatchNapiModuleEndpoint, napiModulesCallEndpoint, } from '@lynx-js/web-constants';
|
|
5
5
|
export const createNapiLoader = async (rpc, napiModulesMap) => {
|
|
6
6
|
const napiModulesCall = rpc.createCall(napiModulesCallEndpoint);
|
|
7
7
|
const napiModules = {};
|
|
8
|
-
await Promise.all(Object.entries(napiModulesMap).map(([moduleName, moduleStr]) => import(/* webpackIgnore: true */ moduleStr).then(module => napiModules[moduleName] = module?.default?.(napiModules, (name, data) => napiModulesCall(name, data, moduleName))
|
|
8
|
+
await Promise.all(Object.entries(napiModulesMap).map(([moduleName, moduleStr]) => import(/* webpackIgnore: true */ moduleStr).then(module => napiModules[moduleName] = module?.default?.(napiModules, (name, data) => napiModulesCall(name, data, moduleName), (func) => {
|
|
9
|
+
rpc.registerHandler(dispatchNapiModuleEndpoint, (data) => func(data));
|
|
10
|
+
}))));
|
|
9
11
|
return {
|
|
10
12
|
load(moduleName) {
|
|
11
13
|
return napiModules[moduleName];
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
2
2
|
import { type LynxTemplate, type NativeApp, type NativeModulesMap } from '@lynx-js/web-constants';
|
|
3
|
+
import type { TimingSystem } from './createTimingSystem.js';
|
|
3
4
|
export declare function createNativeApp(config: {
|
|
4
5
|
template: LynxTemplate;
|
|
5
6
|
uiThreadRpc: Rpc;
|
|
6
7
|
mainThreadRpc: Rpc;
|
|
7
|
-
markTimingInternal: (timingKey: string, pipelineId?: string) => void;
|
|
8
8
|
nativeModulesMap: NativeModulesMap;
|
|
9
|
+
timingSystem: TimingSystem;
|
|
9
10
|
}): Promise<NativeApp>;
|
|
@@ -7,14 +7,13 @@ import { createNativeModules } from './createNativeModules.js';
|
|
|
7
7
|
import { registerUpdateDataHandler } from './crossThreadHandlers/registerUpdateDataHandler.js';
|
|
8
8
|
import { registerPublishEventHandler } from './crossThreadHandlers/registerPublishEventHandler.js';
|
|
9
9
|
import { createPerformanceApis } from './createPerformanceApis.js';
|
|
10
|
-
import { registerPostTimingResultHandler } from './crossThreadHandlers/registerPostTimingResultHandler.js';
|
|
11
10
|
import { registerOnNativeAppReadyHandler } from './crossThreadHandlers/registerOnNativeAppReadyHandler.js';
|
|
12
11
|
import { registerSendGlobalEventHandler } from './crossThreadHandlers/registerSendGlobalEvent.js';
|
|
13
12
|
import { createJSObjectDestructionObserver } from './crossThreadHandlers/createJSObjectDestructionObserver.js';
|
|
14
13
|
let nativeAppCount = 0;
|
|
15
14
|
export async function createNativeApp(config) {
|
|
16
|
-
const { mainThreadRpc, uiThreadRpc,
|
|
17
|
-
const
|
|
15
|
+
const { mainThreadRpc, uiThreadRpc, template, nativeModulesMap, timingSystem, } = config;
|
|
16
|
+
const performanceApis = createPerformanceApis(timingSystem);
|
|
18
17
|
const callLepusMethod = mainThreadRpc.createCallbackify(callLepusMethodEndpoint, 2);
|
|
19
18
|
const setNativeProps = uiThreadRpc.createCall(setNativePropsEndpoint);
|
|
20
19
|
const triggerComponentEvent = uiThreadRpc.createCall(triggerComponentEventEndpoint);
|
|
@@ -26,7 +25,7 @@ export async function createNativeApp(config) {
|
|
|
26
25
|
setInterval: setInterval,
|
|
27
26
|
clearTimeout: clearTimeout,
|
|
28
27
|
clearInterval: clearInterval,
|
|
29
|
-
nativeModuleProxy: await createNativeModules(uiThreadRpc, nativeModulesMap),
|
|
28
|
+
nativeModuleProxy: await createNativeModules(uiThreadRpc, mainThreadRpc, nativeModulesMap),
|
|
30
29
|
loadScriptAsync: function (sourceURL, callback) {
|
|
31
30
|
const mainfestUrl = template.manifest[`/${sourceURL}`];
|
|
32
31
|
if (mainfestUrl)
|
|
@@ -68,13 +67,13 @@ export async function createNativeApp(config) {
|
|
|
68
67
|
invokeUIMethod: createInvokeUIMethod(uiThreadRpc),
|
|
69
68
|
setCard(tt) {
|
|
70
69
|
registerOnLifecycleEventHandler(mainThreadRpc, tt);
|
|
71
|
-
registerPublicComponentEventHandler(
|
|
72
|
-
registerPublishEventHandler(
|
|
73
|
-
registerGlobalExposureEventHandler(
|
|
70
|
+
registerPublicComponentEventHandler(mainThreadRpc, tt);
|
|
71
|
+
registerPublishEventHandler(mainThreadRpc, tt);
|
|
72
|
+
registerGlobalExposureEventHandler(mainThreadRpc, tt);
|
|
74
73
|
registerUpdateDataHandler(uiThreadRpc, tt);
|
|
75
|
-
registerPostTimingResultHandler(uiThreadRpc, tt, pipelineIdToTimingFlags);
|
|
76
74
|
registerOnNativeAppReadyHandler(uiThreadRpc, tt);
|
|
77
75
|
registerSendGlobalEventHandler(uiThreadRpc, tt);
|
|
76
|
+
timingSystem.registerGlobalEmitter(tt.GlobalEventEmitter);
|
|
78
77
|
},
|
|
79
78
|
triggerComponentEvent,
|
|
80
79
|
selectComponent,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type NativeModulesMap } from '@lynx-js/web-constants';
|
|
2
2
|
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
3
|
-
export declare function createNativeModules(
|
|
3
|
+
export declare function createNativeModules(uiThreadRpc: Rpc, mainThreadRpc: Rpc, nativeModulesMap: NativeModulesMap): Promise<Record<string, any>>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { nativeModulesCallEndpoint,
|
|
5
|
-
export async function createNativeModules(
|
|
6
|
-
const switchExposure =
|
|
7
|
-
const nativeModulesCall =
|
|
4
|
+
import { nativeModulesCallEndpoint, switchExposureServiceEndpoint, } from '@lynx-js/web-constants';
|
|
5
|
+
export async function createNativeModules(uiThreadRpc, mainThreadRpc, nativeModulesMap) {
|
|
6
|
+
const switchExposure = mainThreadRpc.createCall(switchExposureServiceEndpoint);
|
|
7
|
+
const nativeModulesCall = uiThreadRpc.createCall(nativeModulesCallEndpoint);
|
|
8
8
|
const lynxExposureModule = {
|
|
9
9
|
resumeExposure() {
|
|
10
10
|
switchExposure(true, true);
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import type { NativeApp } from '@lynx-js/web-constants';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
pipelineIdToTimingFlags: Map<string, string[]>;
|
|
5
|
-
};
|
|
2
|
+
import type { TimingSystem } from './createTimingSystem.js';
|
|
3
|
+
export declare function createPerformanceApis(timingSystem: TimingSystem): Pick<NativeApp, 'generatePipelineOptions' | 'onPipelineStart' | 'markPipelineTiming' | 'bindPipelineIdWithTimingFlag'>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
export function createPerformanceApis(
|
|
4
|
+
export function createPerformanceApis(timingSystem) {
|
|
5
5
|
let inc = 0;
|
|
6
|
-
const pipelineIdToTimingFlags = new Map();
|
|
7
6
|
const performanceApis = {
|
|
8
7
|
generatePipelineOptions: () => {
|
|
9
8
|
const newPipelineId = `_pipeline_` + (inc++);
|
|
@@ -16,19 +15,16 @@ export function createPerformanceApis(markTimingInternal) {
|
|
|
16
15
|
// Do nothing
|
|
17
16
|
},
|
|
18
17
|
markPipelineTiming: function (pipelineId, timingKey) {
|
|
19
|
-
markTimingInternal(timingKey, pipelineId);
|
|
18
|
+
timingSystem.markTimingInternal(timingKey, pipelineId);
|
|
20
19
|
},
|
|
21
20
|
bindPipelineIdWithTimingFlag: function (pipelineId, timingFlag) {
|
|
22
|
-
if (!pipelineIdToTimingFlags.has(pipelineId)) {
|
|
23
|
-
pipelineIdToTimingFlags.set(pipelineId, []);
|
|
21
|
+
if (!timingSystem.pipelineIdToTimingFlags.has(pipelineId)) {
|
|
22
|
+
timingSystem.pipelineIdToTimingFlags.set(pipelineId, []);
|
|
24
23
|
}
|
|
25
|
-
const timingFlags = pipelineIdToTimingFlags.get(pipelineId);
|
|
24
|
+
const timingFlags = timingSystem.pipelineIdToTimingFlags.get(pipelineId);
|
|
26
25
|
timingFlags.push(timingFlag);
|
|
27
26
|
},
|
|
28
27
|
};
|
|
29
|
-
return
|
|
30
|
-
performanceApis,
|
|
31
|
-
pipelineIdToTimingFlags,
|
|
32
|
-
};
|
|
28
|
+
return performanceApis;
|
|
33
29
|
}
|
|
34
30
|
//# sourceMappingURL=createPerformanceApis.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type EventEmitter } from '@lynx-js/web-constants';
|
|
2
|
+
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
3
|
+
export type TimingSystem = {
|
|
4
|
+
registerGlobalEmitter: (globalEventEmitter: EventEmitter) => void;
|
|
5
|
+
markTimingInternal: (timingKey: string, pipelineId?: string) => void;
|
|
6
|
+
pipelineIdToTimingFlags: Map<string, string[]>;
|
|
7
|
+
};
|
|
8
|
+
export declare function createTimingSystem(mainThreadRpc: Rpc, backgroundThreadRpc: Rpc): TimingSystem;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { dispatchLynxViewEventEndpoint, markTimingEndpoint, postTimingFlagsEndpoint, } from '@lynx-js/web-constants';
|
|
5
|
+
const ListenerKeys = {
|
|
6
|
+
onSetup: 'lynx.performance.timing.onSetup',
|
|
7
|
+
onUpdate: 'lynx.performance.timing.onUpdate',
|
|
8
|
+
};
|
|
9
|
+
export function createTimingSystem(mainThreadRpc, backgroundThreadRpc) {
|
|
10
|
+
let isFp = true;
|
|
11
|
+
const setupTiming = {};
|
|
12
|
+
const pipelineIdToTiming = new Map();
|
|
13
|
+
const pipelineIdToTimingFlags = new Map();
|
|
14
|
+
const dispatchLynxViewEvent = backgroundThreadRpc.createCall(dispatchLynxViewEventEndpoint);
|
|
15
|
+
let commonTimingFlags = [];
|
|
16
|
+
function markTimingInternal(timingKey, pipelineId, timeStamp) {
|
|
17
|
+
if (!timeStamp)
|
|
18
|
+
timeStamp = performance.now() + performance.timeOrigin;
|
|
19
|
+
if (!pipelineId) {
|
|
20
|
+
setupTiming[timingKey] = timeStamp;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!pipelineIdToTiming.has(pipelineId)) {
|
|
24
|
+
pipelineIdToTiming.set(pipelineId, {});
|
|
25
|
+
}
|
|
26
|
+
const timingInfo = pipelineIdToTiming.get(pipelineId);
|
|
27
|
+
timingInfo[timingKey] = timeStamp;
|
|
28
|
+
}
|
|
29
|
+
const registerGlobalEmitter = (globalEventEmitter) => {
|
|
30
|
+
mainThreadRpc.registerHandler(postTimingFlagsEndpoint, (timingFlags, pipelineId) => {
|
|
31
|
+
if (!pipelineId) {
|
|
32
|
+
commonTimingFlags = commonTimingFlags.concat(timingFlags);
|
|
33
|
+
}
|
|
34
|
+
else
|
|
35
|
+
timingFlags = timingFlags.concat(commonTimingFlags);
|
|
36
|
+
if (isFp) {
|
|
37
|
+
const timingInfo = {
|
|
38
|
+
extra_timing: {},
|
|
39
|
+
setup_timing: setupTiming,
|
|
40
|
+
update_timings: {},
|
|
41
|
+
metrics: {},
|
|
42
|
+
has_reload: false,
|
|
43
|
+
thread_strategy: 0,
|
|
44
|
+
url: '',
|
|
45
|
+
};
|
|
46
|
+
globalEventEmitter.emit(ListenerKeys.onSetup, [timingInfo]);
|
|
47
|
+
dispatchLynxViewEvent('timing', setupTiming);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const timings = (pipelineId ? pipelineIdToTiming.get(pipelineId) : undefined) ?? {};
|
|
51
|
+
const flags = [
|
|
52
|
+
...timingFlags,
|
|
53
|
+
...(pipelineIdToTimingFlags.get(pipelineId) ?? []),
|
|
54
|
+
];
|
|
55
|
+
const timingInfo = {
|
|
56
|
+
extra_timing: {},
|
|
57
|
+
setup_timing: {},
|
|
58
|
+
update_timings: Object.fromEntries([...flags].map(flag => [flag, timings])),
|
|
59
|
+
metrics: {},
|
|
60
|
+
has_reload: false,
|
|
61
|
+
thread_strategy: 0,
|
|
62
|
+
url: '',
|
|
63
|
+
};
|
|
64
|
+
globalEventEmitter.emit(ListenerKeys.onUpdate, [timingInfo]);
|
|
65
|
+
dispatchLynxViewEvent('timing', timings);
|
|
66
|
+
}
|
|
67
|
+
if (pipelineId) {
|
|
68
|
+
pipelineIdToTimingFlags.delete(pipelineId);
|
|
69
|
+
pipelineIdToTiming.delete(pipelineId);
|
|
70
|
+
}
|
|
71
|
+
if (isFp) {
|
|
72
|
+
isFp = false;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
mainThreadRpc.registerHandler(markTimingEndpoint, markTimingInternal);
|
|
77
|
+
backgroundThreadRpc.registerHandler(markTimingEndpoint, markTimingInternal);
|
|
78
|
+
return {
|
|
79
|
+
markTimingInternal,
|
|
80
|
+
registerGlobalEmitter,
|
|
81
|
+
pipelineIdToTimingFlags,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=createTimingSystem.js.map
|
|
@@ -5,23 +5,23 @@ import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
|
5
5
|
import { createBackgroundLynx } from './createBackgroundLynx.js';
|
|
6
6
|
import { createNativeApp } from './createNativeApp.js';
|
|
7
7
|
import { registerDisposeHandler } from './crossThreadHandlers/registerDisposeHandler.js';
|
|
8
|
-
import { createMarkTimingInternal } from './crossThreadHandlers/createBackgroundMarkTimingInternal.js';
|
|
9
8
|
import { BackgroundThreadStartEndpoint } from '@lynx-js/web-constants';
|
|
10
9
|
import { createNapiLoader } from './createNapiLoader.js';
|
|
10
|
+
import { createTimingSystem } from './createTimingSystem.js';
|
|
11
11
|
const lynxCore = import(
|
|
12
12
|
/* webpackMode: "eager" */ '@lynx-js/lynx-core/web');
|
|
13
13
|
export function startBackgroundThread(uiThreadPort, mainThreadPort) {
|
|
14
14
|
const uiThreadRpc = new Rpc(uiThreadPort, 'bg-to-ui');
|
|
15
15
|
const mainThreadRpc = new Rpc(mainThreadPort, 'bg-to-main');
|
|
16
|
-
const
|
|
17
|
-
markTimingInternal('load_core_start');
|
|
16
|
+
const timingSystem = createTimingSystem(mainThreadRpc, uiThreadRpc);
|
|
17
|
+
timingSystem.markTimingInternal('load_core_start');
|
|
18
18
|
mainThreadRpc.registerHandler(BackgroundThreadStartEndpoint, async (config) => {
|
|
19
|
-
markTimingInternal('load_core_end');
|
|
19
|
+
timingSystem.markTimingInternal('load_core_end');
|
|
20
20
|
const nativeApp = await createNativeApp({
|
|
21
21
|
...config,
|
|
22
22
|
uiThreadRpc,
|
|
23
23
|
mainThreadRpc,
|
|
24
|
-
|
|
24
|
+
timingSystem,
|
|
25
25
|
});
|
|
26
26
|
globalThis['napiLoaderOnRT' + nativeApp.id] =
|
|
27
27
|
await createNapiLoader(uiThreadRpc, config.napiModulesMap);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import {
|
|
4
|
+
import { markTimingEndpoint } from '@lynx-js/web-constants';
|
|
5
5
|
export function createMarkTimingInternal(uiThreadRpc) {
|
|
6
6
|
return (timingKey, pipelineId) => {
|
|
7
|
-
uiThreadRpc.invoke(
|
|
7
|
+
uiThreadRpc.invoke(markTimingEndpoint, [
|
|
8
8
|
timingKey,
|
|
9
9
|
pipelineId,
|
|
10
10
|
performance.now() + performance.timeOrigin,
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { BackgroundThreadStartEndpoint, mainThreadChunkReadyEndpoint, mainThreadStartEndpoint, onLifecycleEventEndpoint, flushElementTreeEndpoint, reportErrorEndpoint, } from '@lynx-js/web-constants';
|
|
4
|
+
import { BackgroundThreadStartEndpoint, mainThreadChunkReadyEndpoint, mainThreadStartEndpoint, onLifecycleEventEndpoint, flushElementTreeEndpoint, reportErrorEndpoint, publishEventEndpoint, publicComponentEventEndpoint, postExposureEndpoint, postOffscreenEventEndpoint, switchExposureServiceEndpoint, postTimingFlagsEndpoint, } from '@lynx-js/web-constants';
|
|
5
5
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
6
|
-
import { MainThreadRuntime } from '@lynx-js/web-mainthread-apis';
|
|
6
|
+
import { MainThreadRuntime, switchExposureService, } from '@lynx-js/web-mainthread-apis';
|
|
7
7
|
import { registerCallLepusMethodHandler } from './crossThreadHandlers/registerCallLepusMethodHandler.js';
|
|
8
|
-
import { registerPostMainThreadEventHandler } from './crossThreadHandlers/registerPostMainThreadEventHandler.js';
|
|
9
8
|
import { registerGetCustomSectionHandler } from './crossThreadHandlers/registerGetCustomSectionHandler.js';
|
|
10
9
|
import { createMarkTimingInternal } from './crossThreadHandlers/createMainthreadMarkTimingInternal.js';
|
|
11
10
|
import { registerUpdateDataHandler } from './crossThreadHandlers/registerUpdateDataHandler.js';
|
|
11
|
+
import { OffscreenDocument } from '@lynx-js/offscreen-document/webworker';
|
|
12
|
+
import { _onEvent, } from '@lynx-js/offscreen-document/webworker';
|
|
12
13
|
export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
13
14
|
const uiThreadRpc = new Rpc(uiThreadPort, 'main-to-ui');
|
|
14
15
|
const backgroundThreadRpc = new Rpc(backgroundThreadPort, 'main-to-bg');
|
|
15
|
-
const markTimingInternal = createMarkTimingInternal(
|
|
16
|
+
const markTimingInternal = createMarkTimingInternal(backgroundThreadRpc);
|
|
17
|
+
const postTimingFlags = backgroundThreadRpc.createCall(postTimingFlagsEndpoint);
|
|
16
18
|
const backgroundStart = backgroundThreadRpc.createCall(BackgroundThreadStartEndpoint);
|
|
17
19
|
const __OnLifecycleEvent = backgroundThreadRpc.createCall(onLifecycleEventEndpoint);
|
|
20
|
+
const publishEvent = backgroundThreadRpc.createCall(publishEventEndpoint);
|
|
21
|
+
const publicComponentEvent = backgroundThreadRpc.createCall(publicComponentEventEndpoint);
|
|
22
|
+
const postExposure = backgroundThreadRpc.createCall(postExposureEndpoint);
|
|
18
23
|
const mainThreadChunkReady = uiThreadRpc.createCall(mainThreadChunkReadyEndpoint);
|
|
24
|
+
let operations = [];
|
|
19
25
|
const flushElementTree = uiThreadRpc.createCall(flushElementTreeEndpoint);
|
|
20
26
|
const reportError = uiThreadRpc.createCall(reportErrorEndpoint);
|
|
21
27
|
markTimingInternal('lepus_excute_start');
|
|
@@ -26,6 +32,12 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
|
26
32
|
await import(
|
|
27
33
|
/* webpackIgnore: true */ template.lepusCode.root);
|
|
28
34
|
const entry = globalThis.module.exports;
|
|
35
|
+
const docu = new OffscreenDocument({
|
|
36
|
+
onCommit: (currentOperations) => {
|
|
37
|
+
operations = currentOperations;
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
uiThreadRpc.registerHandler(postOffscreenEventEndpoint, docu[_onEvent]);
|
|
29
41
|
const runtime = new MainThreadRuntime({
|
|
30
42
|
tagMap,
|
|
31
43
|
browserConfig,
|
|
@@ -34,18 +46,19 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
|
34
46
|
pageConfig,
|
|
35
47
|
styleInfo,
|
|
36
48
|
lepusCode,
|
|
49
|
+
docu,
|
|
37
50
|
callbacks: {
|
|
38
51
|
mainChunkReady: function () {
|
|
39
|
-
mainThreadChunkReady(
|
|
52
|
+
mainThreadChunkReady();
|
|
40
53
|
markTimingInternal('data_processor_start');
|
|
41
54
|
const initData = runtime.processData
|
|
42
55
|
? runtime.processData(config.initData)
|
|
43
56
|
: config.initData;
|
|
44
57
|
markTimingInternal('data_processor_end');
|
|
45
58
|
registerCallLepusMethodHandler(backgroundThreadRpc, runtime);
|
|
46
|
-
registerPostMainThreadEventHandler(uiThreadRpc);
|
|
47
59
|
registerGetCustomSectionHandler(backgroundThreadRpc, customSections);
|
|
48
60
|
registerUpdateDataHandler(uiThreadRpc, runtime);
|
|
61
|
+
backgroundThreadRpc.registerHandler(switchExposureServiceEndpoint, runtime[switchExposureService]);
|
|
49
62
|
backgroundStart({
|
|
50
63
|
initData,
|
|
51
64
|
globalProps,
|
|
@@ -58,7 +71,18 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
|
58
71
|
runtime.renderPage(initData);
|
|
59
72
|
runtime.__FlushElementTree(undefined, {});
|
|
60
73
|
},
|
|
61
|
-
flushElementTree,
|
|
74
|
+
flushElementTree: async (options, timingFlags) => {
|
|
75
|
+
const pipelineId = options?.pipelineOptions?.pipelineID;
|
|
76
|
+
markTimingInternal('dispatch_start', pipelineId);
|
|
77
|
+
docu.commit();
|
|
78
|
+
markTimingInternal('layout_start', pipelineId);
|
|
79
|
+
markTimingInternal('ui_operation_flush_start', pipelineId);
|
|
80
|
+
await flushElementTree(operations);
|
|
81
|
+
markTimingInternal('ui_operation_flush_end', pipelineId);
|
|
82
|
+
markTimingInternal('layout_end', pipelineId);
|
|
83
|
+
markTimingInternal('dispatch_end', pipelineId);
|
|
84
|
+
postTimingFlags(timingFlags, pipelineId);
|
|
85
|
+
},
|
|
62
86
|
_ReportError: reportError,
|
|
63
87
|
__OnLifecycleEvent,
|
|
64
88
|
/**
|
|
@@ -67,6 +91,9 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
|
67
91
|
* But our markTimingInternal is (timingFlag:string, pipelineId?:string, timeStamp?:number) => void
|
|
68
92
|
*/
|
|
69
93
|
markTiming: (a, b) => markTimingInternal(b, a),
|
|
94
|
+
publishEvent,
|
|
95
|
+
publicComponentEvent,
|
|
96
|
+
postExposure,
|
|
70
97
|
},
|
|
71
98
|
}).globalThis;
|
|
72
99
|
markTimingInternal('decode_end');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-worker-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -22,9 +22,10 @@
|
|
|
22
22
|
"README.md"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@lynx-js/
|
|
26
|
-
"@lynx-js/web-
|
|
27
|
-
"@lynx-js/web-mainthread-apis": "0.
|
|
25
|
+
"@lynx-js/offscreen-document": "0.0.0",
|
|
26
|
+
"@lynx-js/web-constants": "0.10.1",
|
|
27
|
+
"@lynx-js/web-mainthread-apis": "0.10.1",
|
|
28
|
+
"@lynx-js/web-worker-rpc": "0.10.1"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@lynx-js/lynx-core": "0.1.0"
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
|
-
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
-
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { postTimingInfoFromBackgroundThread } from '@lynx-js/web-constants';
|
|
5
|
-
export function createMarkTimingInternal(backgroundRpc) {
|
|
6
|
-
return (timingKey, pipelineId) => {
|
|
7
|
-
backgroundRpc.invoke(postTimingInfoFromBackgroundThread, [
|
|
8
|
-
timingKey,
|
|
9
|
-
pipelineId,
|
|
10
|
-
performance.now() + performance.timeOrigin,
|
|
11
|
-
]);
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=createBackgroundMarkTimingInternal.js.map
|
package/dist/backgroundThread/background-apis/crossThreadHandlers/registerPostTimingResultHandler.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
|
-
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
-
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { postTimingResult, } from '@lynx-js/web-constants';
|
|
5
|
-
const ListenerKeys = {
|
|
6
|
-
onSetup: 'lynx.performance.timing.onSetup',
|
|
7
|
-
onUpdate: 'lynx.performance.timing.onUpdate',
|
|
8
|
-
};
|
|
9
|
-
export function registerPostTimingResultHandler(uiThreadRpc, tt, pipelineIdToTimingFlags) {
|
|
10
|
-
let setupTimingSaved = {};
|
|
11
|
-
uiThreadRpc.registerHandler(postTimingResult, (pipelineId, updateTimingStamps, timingFlags, setupTimingStamps) => {
|
|
12
|
-
if (setupTimingStamps) {
|
|
13
|
-
setupTimingSaved = setupTimingStamps;
|
|
14
|
-
const timingInfo = {
|
|
15
|
-
extra_timing: {},
|
|
16
|
-
setup_timing: setupTimingStamps,
|
|
17
|
-
update_timings: {},
|
|
18
|
-
metrics: {},
|
|
19
|
-
has_reload: false,
|
|
20
|
-
thread_strategy: 0,
|
|
21
|
-
url: '',
|
|
22
|
-
};
|
|
23
|
-
tt.GlobalEventEmitter.emit(ListenerKeys.onSetup, [timingInfo]);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
const flags = [
|
|
27
|
-
...timingFlags,
|
|
28
|
-
...(pipelineIdToTimingFlags.get(pipelineId) ?? []),
|
|
29
|
-
];
|
|
30
|
-
const timingInfo = {
|
|
31
|
-
extra_timing: {},
|
|
32
|
-
setup_timing: setupTimingSaved,
|
|
33
|
-
update_timings: Object.fromEntries([...flags].map(flag => [flag, updateTimingStamps])),
|
|
34
|
-
metrics: {},
|
|
35
|
-
has_reload: false,
|
|
36
|
-
thread_strategy: 0,
|
|
37
|
-
url: '',
|
|
38
|
-
};
|
|
39
|
-
tt.GlobalEventEmitter.emit(ListenerKeys.onUpdate, [timingInfo]);
|
|
40
|
-
}
|
|
41
|
-
if (pipelineId) {
|
|
42
|
-
pipelineIdToTimingFlags.delete(pipelineId);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=registerPostTimingResultHandler.js.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ElementThreadElement } from '@lynx-js/web-mainthread-apis';
|
|
2
|
-
import { postMainThreadEvent } from '@lynx-js/web-constants';
|
|
3
|
-
export function registerPostMainThreadEventHandler(rpc) {
|
|
4
|
-
rpc.registerHandler(postMainThreadEvent, (event) => {
|
|
5
|
-
ElementThreadElement.receiveEvent(event);
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=registerPostMainThreadEventHandler.js.map
|