-
Notifications
You must be signed in to change notification settings - Fork 122
feat: support thread strategy all on ui #625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
257a9ac
feat: support thread strategy `all-on-ui`
PupilTong 1c40290
all on ui tests
PupilTong 7079025
fix
PupilTong e6d3eec
update changeset
PupilTong 6bf7962
Update .changeset/giant-seas-leave.md
PupilTong 74c4a7c
add changeset
PupilTong 56c1600
accept comments
PupilTong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| --- | ||
| "@lynx-js/web-mainthread-apis": patch | ||
| "@lynx-js/web-worker-runtime": patch | ||
| "@lynx-js/web-core": patch | ||
| --- | ||
|
|
||
| feat: support thread strategy `all-on-ui` | ||
|
|
||
| ```html | ||
| <lynx-view thread-strategy="all-on-ui"></lynx-view> | ||
| ``` | ||
|
|
||
| This will make the lynx's main-thread run on the UA's main thread. | ||
|
|
||
| Note that the `all-on-ui` does not support the HMR & chunk splitting yet. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@lynx-js/offscreen-document": patch | ||
| --- | ||
|
|
||
| feat: support parentNode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/web-platform/web-core/src/uiThread/createRenderAllOnUI.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import type { | ||
| MainThreadStartConfigs, | ||
| RpcCallType, | ||
| updateDataEndpoint, | ||
| } from '@lynx-js/web-constants'; | ||
| import type { MainThreadRuntime } from '@lynx-js/web-mainthread-apis'; | ||
| import { Rpc } from '@lynx-js/web-worker-rpc'; | ||
|
|
||
| const { | ||
| loadMainThread, | ||
| } = await import('@lynx-js/web-mainthread-apis'); | ||
|
|
||
| export function createRenderAllOnUI( | ||
| mainToBackgroundRpc: Rpc, | ||
| shadowRoot: ShadowRoot, | ||
| markTimingInternal: ( | ||
| timingKey: string, | ||
| pipelineId?: string, | ||
| timeStamp?: number, | ||
| ) => void, | ||
| callbacks: { | ||
| onError?: () => void; | ||
| }, | ||
| ) { | ||
| if (!globalThis.module) { | ||
| Object.assign(globalThis, { module: {} }); | ||
| } | ||
| const docu = Object.assign(shadowRoot, { | ||
| createElement: document.createElement.bind(document), | ||
| }); | ||
| const { startMainThread } = loadMainThread( | ||
| mainToBackgroundRpc, | ||
| docu, | ||
| () => {}, | ||
| markTimingInternal, | ||
| () => { | ||
| callbacks.onError?.(); | ||
| }, | ||
| ); | ||
| let runtime!: MainThreadRuntime; | ||
| const start = async (configs: MainThreadStartConfigs) => { | ||
| const mainThreadRuntime = startMainThread(configs); | ||
| runtime = await mainThreadRuntime; | ||
| }; | ||
| const updateDataMainThread: RpcCallType<typeof updateDataEndpoint> = async ( | ||
| ...args | ||
| ) => { | ||
| runtime.updatePage?.(...args); | ||
| }; | ||
| return { | ||
| start, | ||
| updateDataMainThread, | ||
| }; | ||
| } |
32 changes: 32 additions & 0 deletions
32
packages/web-platform/web-core/src/uiThread/createRenderMultiThread.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { | ||
| mainThreadStartEndpoint, | ||
| updateDataEndpoint, | ||
| } from '@lynx-js/web-constants'; | ||
| import type { Rpc } from '@lynx-js/web-worker-rpc'; | ||
| import { registerReportErrorHandler } from './crossThreadHandlers/registerReportErrorHandler.js'; | ||
| import { registerFlushElementTreeHandler } from './crossThreadHandlers/registerFlushElementTreeHandler.js'; | ||
|
|
||
| export function createRenderMultiThread( | ||
| mainThreadRpc: Rpc, | ||
| shadowRoot: ShadowRoot, | ||
| callbacks: { | ||
| onError?: () => void; | ||
| }, | ||
| ) { | ||
| registerReportErrorHandler( | ||
| mainThreadRpc, | ||
| callbacks.onError, | ||
| ); | ||
| registerFlushElementTreeHandler( | ||
| mainThreadRpc, | ||
| { | ||
| shadowRoot, | ||
| }, | ||
| ); | ||
| const start = mainThreadRpc.createCall(mainThreadStartEndpoint); | ||
| const updateDataMainThread = mainThreadRpc.createCall(updateDataEndpoint); | ||
| return { | ||
| start, | ||
| updateDataMainThread, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/web-platform/web-core/src/uiThread/startBackground.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { | ||
| markTimingEndpoint, | ||
| sendGlobalEventEndpoint, | ||
| updateDataEndpoint, | ||
| type NapiModulesCall, | ||
| type NativeModulesCall, | ||
| } from '@lynx-js/web-constants'; | ||
| import type { Rpc } from '@lynx-js/web-worker-rpc'; | ||
| import { registerInvokeUIMethodHandler } from './crossThreadHandlers/registerInvokeUIMethodHandler.js'; | ||
| import { registerNativePropsHandler } from './crossThreadHandlers/registerSetNativePropsHandler.js'; | ||
| import { registerNativeModulesCallHandler } from './crossThreadHandlers/registerNativeModulesCallHandler.js'; | ||
| import { registerTriggerComponentEventHandler } from './crossThreadHandlers/registerTriggerComponentEventHandler.js'; | ||
| import { registerSelectComponentHandler } from './crossThreadHandlers/registerSelectComponentHandler.js'; | ||
| import { registerNapiModulesCallHandler } from './crossThreadHandlers/registerNapiModulesCallHandler.js'; | ||
| import { registerDispatchLynxViewEventHandler } from './crossThreadHandlers/registerDispatchLynxViewEventHandler.js'; | ||
|
|
||
| export function startBackground( | ||
| backgroundRpc: Rpc, | ||
| shadowRoot: ShadowRoot, | ||
| callbacks: { | ||
| nativeModulesCall: NativeModulesCall; | ||
| napiModulesCall: NapiModulesCall; | ||
| }, | ||
| ) { | ||
| registerInvokeUIMethodHandler( | ||
| backgroundRpc, | ||
| shadowRoot, | ||
| ); | ||
| registerNativePropsHandler( | ||
| backgroundRpc, | ||
| shadowRoot, | ||
| ); | ||
| registerTriggerComponentEventHandler( | ||
| backgroundRpc, | ||
| shadowRoot, | ||
| ); | ||
| registerSelectComponentHandler( | ||
| backgroundRpc, | ||
| shadowRoot, | ||
| ); | ||
| registerNativeModulesCallHandler( | ||
| backgroundRpc, | ||
| callbacks.nativeModulesCall, | ||
| ); | ||
| registerNapiModulesCallHandler( | ||
| backgroundRpc, | ||
| callbacks.napiModulesCall, | ||
| ); | ||
| registerDispatchLynxViewEventHandler(backgroundRpc, shadowRoot); | ||
|
|
||
| const sendGlobalEvent = backgroundRpc.createCall(sendGlobalEventEndpoint); | ||
| const markTiming = backgroundRpc.createCall(markTimingEndpoint); | ||
| const updateDataBackground = backgroundRpc.createCall(updateDataEndpoint); | ||
| return { | ||
| sendGlobalEvent, | ||
| markTiming, | ||
| updateDataBackground, | ||
| }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.