@lynx-js/web-worker-runtime 0.14.1 → 0.15.0
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 +70 -0
- package/dist/backgroundThread/background-apis/createNapiLoader.js +2 -0
- package/dist/backgroundThread/background-apis/createTimingSystem.d.ts +1 -1
- package/dist/backgroundThread/background-apis/createTimingSystem.js +17 -15
- package/dist/mainThread/crossThreadHandlers/createMainthreadMarkTimingInternal.d.ts +4 -1
- package/dist/mainThread/crossThreadHandlers/createMainthreadMarkTimingInternal.js +18 -8
- package/dist/mainThread/startMainThread.js +9 -3
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,75 @@
|
|
|
1
1
|
# @lynx-js/web-worker-runtime
|
|
2
2
|
|
|
3
|
+
## 0.15.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- refactor: move exposure system to web-core ([#1254](https://github.com/lynx-family/lynx-stack/pull/1254))
|
|
8
|
+
|
|
9
|
+
**THIS IS A BREAKING CHANGE**
|
|
10
|
+
|
|
11
|
+
**You'll need to upgrade your @lynx-js/web-elements to >= 0.8.0**
|
|
12
|
+
|
|
13
|
+
For SSR and better performance, we moved the lynx's exposure system from web-element to web-core.
|
|
14
|
+
|
|
15
|
+
Before this commit, we create Intersection observers by creating HTMLElements.
|
|
16
|
+
|
|
17
|
+
After this commit, we will create such Intersection observers after dom stabled.
|
|
18
|
+
|
|
19
|
+
Also, the setInterval for exposure has been removed, now we use an on time lazy timer for such features.
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- feat: add `napiModulesPath` to bundle napiModules into worker runtime. ([#1134](https://github.com/lynx-family/lynx-stack/pull/1134))
|
|
24
|
+
|
|
25
|
+
Usage:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { pluginWebPlatform } from '@lynx-js/web-platform-rsbuild-plugin';
|
|
29
|
+
import { defineConfig } from '@rsbuild/core';
|
|
30
|
+
|
|
31
|
+
export default defineConfig({
|
|
32
|
+
plugins: [
|
|
33
|
+
pluginWebPlatform({
|
|
34
|
+
// replace with your actual napi-modules file path
|
|
35
|
+
napiModulesPath: path.resolve(__dirname, './index.napi-modules.ts'),
|
|
36
|
+
}),
|
|
37
|
+
],
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`napi-modules.ts` example:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
// index.napi-modules.ts
|
|
45
|
+
export default {
|
|
46
|
+
custom_module: function(NapiModules, NapiModulesCall) {
|
|
47
|
+
return {
|
|
48
|
+
async test(name) {
|
|
49
|
+
console.log('CustomModule', NapiModules, NapiModulesCall);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
- Updated dependencies [[`7b75469`](https://github.com/lynx-family/lynx-stack/commit/7b75469d05dd2ec78bf6e1e54b94c8dff938eb40), [`224c653`](https://github.com/lynx-family/lynx-stack/commit/224c653f370d807281fa0a9ffbb4f4dd5c9d308e)]:
|
|
57
|
+
- @lynx-js/offscreen-document@0.1.3
|
|
58
|
+
- @lynx-js/web-mainthread-apis@0.15.0
|
|
59
|
+
- @lynx-js/web-constants@0.15.0
|
|
60
|
+
- @lynx-js/web-worker-rpc@0.15.0
|
|
61
|
+
|
|
62
|
+
## 0.14.2
|
|
63
|
+
|
|
64
|
+
### Patch Changes
|
|
65
|
+
|
|
66
|
+
- feat: merge multiple markTiming RPC communication events together and send them together, which can effectively reduce the number of RPC communications. ([#1178](https://github.com/lynx-family/lynx-stack/pull/1178))
|
|
67
|
+
|
|
68
|
+
- Updated dependencies [[`e44b146`](https://github.com/lynx-family/lynx-stack/commit/e44b146b1bc2b58c0347af7fb4e4157688e07e36), [`5a9b38b`](https://github.com/lynx-family/lynx-stack/commit/5a9b38b783e611aa9761c4cd52191172270c09c7), [`6ca5b91`](https://github.com/lynx-family/lynx-stack/commit/6ca5b9106aade393dfac88914b160960a61a82f2)]:
|
|
69
|
+
- @lynx-js/web-mainthread-apis@0.14.2
|
|
70
|
+
- @lynx-js/web-constants@0.14.2
|
|
71
|
+
- @lynx-js/web-worker-rpc@0.14.2
|
|
72
|
+
|
|
3
73
|
## 0.14.1
|
|
4
74
|
|
|
5
75
|
### Patch Changes
|
|
@@ -1,6 +1,7 @@
|
|
|
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
|
+
/* LYNX_NAPI_MODULES_IMPORT */
|
|
4
5
|
import { dispatchNapiModuleEndpoint, napiModulesCallEndpoint, } from '@lynx-js/web-constants';
|
|
5
6
|
export const createNapiLoader = async (rpc, napiModulesMap) => {
|
|
6
7
|
const napiModulesCall = rpc.createCall(napiModulesCallEndpoint);
|
|
@@ -8,6 +9,7 @@ export const createNapiLoader = async (rpc, napiModulesMap) => {
|
|
|
8
9
|
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
10
|
rpc.registerHandler(dispatchNapiModuleEndpoint, (data) => func(data));
|
|
10
11
|
}))));
|
|
12
|
+
/* LYNX_NAPI_MODULES_ADD */
|
|
11
13
|
return {
|
|
12
14
|
load(moduleName) {
|
|
13
15
|
return napiModules[moduleName];
|
|
@@ -5,4 +5,4 @@ export type TimingSystem = {
|
|
|
5
5
|
markTimingInternal: (timingKey: string, pipelineId?: string) => void;
|
|
6
6
|
pipelineIdToTimingFlags: Map<string, string[]>;
|
|
7
7
|
};
|
|
8
|
-
export declare function createTimingSystem(mainThreadRpc: Rpc,
|
|
8
|
+
export declare function createTimingSystem(mainThreadRpc: Rpc, uiThreadRpc: Rpc): TimingSystem;
|
|
@@ -6,25 +6,27 @@ const ListenerKeys = {
|
|
|
6
6
|
onSetup: 'lynx.performance.timing.onSetup',
|
|
7
7
|
onUpdate: 'lynx.performance.timing.onUpdate',
|
|
8
8
|
};
|
|
9
|
-
export function createTimingSystem(mainThreadRpc,
|
|
9
|
+
export function createTimingSystem(mainThreadRpc, uiThreadRpc) {
|
|
10
10
|
let isFp = true;
|
|
11
11
|
const setupTiming = {};
|
|
12
12
|
const pipelineIdToTiming = new Map();
|
|
13
13
|
const pipelineIdToTimingFlags = new Map();
|
|
14
|
-
const dispatchLynxViewEvent =
|
|
14
|
+
const dispatchLynxViewEvent = uiThreadRpc.createCall(dispatchLynxViewEventEndpoint);
|
|
15
15
|
let commonTimingFlags = [];
|
|
16
|
-
function markTimingInternal(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
pipelineIdToTiming.
|
|
16
|
+
function markTimingInternal(markTimingRecords) {
|
|
17
|
+
for (let { timingKey, pipelineId, timeStamp } of markTimingRecords) {
|
|
18
|
+
if (!timeStamp)
|
|
19
|
+
timeStamp = performance.now() + performance.timeOrigin;
|
|
20
|
+
if (!pipelineId) {
|
|
21
|
+
setupTiming[timingKey] = timeStamp;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (!pipelineIdToTiming.has(pipelineId)) {
|
|
25
|
+
pipelineIdToTiming.set(pipelineId, {});
|
|
26
|
+
}
|
|
27
|
+
const timingInfo = pipelineIdToTiming.get(pipelineId);
|
|
28
|
+
timingInfo[timingKey] = timeStamp;
|
|
25
29
|
}
|
|
26
|
-
const timingInfo = pipelineIdToTiming.get(pipelineId);
|
|
27
|
-
timingInfo[timingKey] = timeStamp;
|
|
28
30
|
}
|
|
29
31
|
const registerGlobalEmitter = (globalEventEmitter) => {
|
|
30
32
|
mainThreadRpc.registerHandler(postTimingFlagsEndpoint, (timingFlags, pipelineId) => {
|
|
@@ -74,9 +76,9 @@ export function createTimingSystem(mainThreadRpc, backgroundThreadRpc) {
|
|
|
74
76
|
});
|
|
75
77
|
};
|
|
76
78
|
mainThreadRpc.registerHandler(markTimingEndpoint, markTimingInternal);
|
|
77
|
-
|
|
79
|
+
uiThreadRpc.registerHandler(markTimingEndpoint, markTimingInternal);
|
|
78
80
|
return {
|
|
79
|
-
markTimingInternal,
|
|
81
|
+
markTimingInternal: (timingKey, pipelineId, timeStamp) => markTimingInternal([{ timingKey, pipelineId, timeStamp }]),
|
|
80
82
|
registerGlobalEmitter,
|
|
81
83
|
pipelineIdToTimingFlags,
|
|
82
84
|
};
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
2
|
-
export declare function createMarkTimingInternal(
|
|
2
|
+
export declare function createMarkTimingInternal(backgroundThreadRpc: Rpc): {
|
|
3
|
+
markTimingInternal: (timingKey: string, pipelineId?: string, timeStamp?: number) => void;
|
|
4
|
+
flushMarkTimingInternal: () => void;
|
|
5
|
+
};
|
|
@@ -1,14 +1,24 @@
|
|
|
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 { markTimingEndpoint } from '@lynx-js/web-constants';
|
|
5
|
-
export function createMarkTimingInternal(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
import { dispatchMarkTiming, flushMarkTiming, markTimingEndpoint, } from '@lynx-js/web-constants';
|
|
5
|
+
export function createMarkTimingInternal(backgroundThreadRpc) {
|
|
6
|
+
const markTiming = backgroundThreadRpc.createCall(markTimingEndpoint);
|
|
7
|
+
const cacheMarkTimings = {
|
|
8
|
+
records: [],
|
|
9
|
+
timeout: null,
|
|
10
|
+
};
|
|
11
|
+
return {
|
|
12
|
+
markTimingInternal: (timingKey, pipelineId, timeStamp) => {
|
|
13
|
+
dispatchMarkTiming({
|
|
14
|
+
timingKey,
|
|
15
|
+
pipelineId,
|
|
16
|
+
timeStamp,
|
|
17
|
+
markTiming,
|
|
18
|
+
cacheMarkTimings,
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
flushMarkTimingInternal: () => flushMarkTiming(markTiming, cacheMarkTimings),
|
|
12
22
|
};
|
|
13
23
|
}
|
|
14
24
|
//# sourceMappingURL=createMainthreadMarkTimingInternal.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
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 { flushElementTreeEndpoint, mainThreadStartEndpoint, postOffscreenEventEndpoint, reportErrorEndpoint, dispatchLynxViewEventEndpoint, i18nResourceMissedEventName, I18nResources, updateI18nResourcesEndpoint, } from '@lynx-js/web-constants';
|
|
4
|
+
import { flushElementTreeEndpoint, mainThreadStartEndpoint, postOffscreenEventEndpoint, reportErrorEndpoint, dispatchLynxViewEventEndpoint, i18nResourceMissedEventName, I18nResources, updateI18nResourcesEndpoint, multiThreadExposureChangedEndpoint, lynxUniqueIdAttribute, } from '@lynx-js/web-constants';
|
|
5
5
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
6
6
|
import { createMarkTimingInternal } from './crossThreadHandlers/createMainthreadMarkTimingInternal.js';
|
|
7
7
|
import { OffscreenDocument } from '@lynx-js/offscreen-document/webworker';
|
|
@@ -11,7 +11,7 @@ const { prepareMainThreadAPIs } = await import('@lynx-js/web-mainthread-apis');
|
|
|
11
11
|
export function startMainThreadWorker(uiThreadPort, backgroundThreadPort) {
|
|
12
12
|
const uiThreadRpc = new Rpc(uiThreadPort, 'main-to-ui');
|
|
13
13
|
const backgroundThreadRpc = new Rpc(backgroundThreadPort, 'main-to-bg');
|
|
14
|
-
const markTimingInternal = createMarkTimingInternal(backgroundThreadRpc);
|
|
14
|
+
const { markTimingInternal, flushMarkTimingInternal } = createMarkTimingInternal(backgroundThreadRpc);
|
|
15
15
|
const uiFlush = uiThreadRpc.createCall(flushElementTreeEndpoint);
|
|
16
16
|
const reportError = uiThreadRpc.createCall(reportErrorEndpoint);
|
|
17
17
|
const triggerI18nResourceFallback = (options) => {
|
|
@@ -25,7 +25,13 @@ export function startMainThreadWorker(uiThreadPort, backgroundThreadPort) {
|
|
|
25
25
|
});
|
|
26
26
|
const i18nResources = new I18nResources();
|
|
27
27
|
uiThreadRpc.registerHandler(postOffscreenEventEndpoint, docu[_onEvent]);
|
|
28
|
-
const
|
|
28
|
+
const sendMultiThreadExposureChangedEndpoint = uiThreadRpc.createCall(multiThreadExposureChangedEndpoint);
|
|
29
|
+
const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc, docu, docu.createElement.bind(docu), (exposureChangedElementUniqueIds) => {
|
|
30
|
+
docu.commit();
|
|
31
|
+
sendMultiThreadExposureChangedEndpoint(exposureChangedElementUniqueIds
|
|
32
|
+
.map(e => e.getAttribute(lynxUniqueIdAttribute))
|
|
33
|
+
.filter(id => id !== null));
|
|
34
|
+
}, markTimingInternal, flushMarkTimingInternal, reportError, triggerI18nResourceFallback, (initI18nResources) => {
|
|
29
35
|
i18nResources.setData(initI18nResources);
|
|
30
36
|
return i18nResources;
|
|
31
37
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-worker-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"README.md"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@lynx-js/offscreen-document": "0.1.
|
|
26
|
-
"@lynx-js/web-constants": "0.
|
|
27
|
-
"@lynx-js/web-mainthread-apis": "0.
|
|
28
|
-
"@lynx-js/web-worker-rpc": "0.
|
|
25
|
+
"@lynx-js/offscreen-document": "0.1.3",
|
|
26
|
+
"@lynx-js/web-constants": "0.15.0",
|
|
27
|
+
"@lynx-js/web-mainthread-apis": "0.15.0",
|
|
28
|
+
"@lynx-js/web-worker-rpc": "0.15.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@lynx-js/lynx-core": "0.1.2"
|