Skip to content

feat: add dedicated JavaScript thread support#512

Merged
andycall merged 69 commits into
mainfrom
feat/feat/dedicated_js_thread_v2
Dec 28, 2023
Merged

feat: add dedicated JavaScript thread support#512
andycall merged 69 commits into
mainfrom
feat/feat/dedicated_js_thread_v2

Conversation

@andycall
Copy link
Copy Markdown
Member

@andycall andycall commented Oct 31, 2023

RFC: openwebf/rfc#4

First version implemented by @penneryu and improved by @andycall

Use example:

DedicatedThreadGroup threadGroup = DedicatedThreadGroup();

WebF(
  bundle: WebFBundle.fromUrl('assets:assets/bundle.html'),
  runningThread: DedicatedThread(), //  Executes your JavaScript code in a dedicated thread
),
WebF(
  bundle: WebFBundle.fromUrl('assets:assets/bundle.html'),
  runningThread: FlutterUIThread(), // Executes your JavaScript code within the Flutter UI thread.
),
WebF(
  bundle: WebFBundle.fromUrl('assets:assets/bundle.html'),
  runningThread: FlutterUIThread(), // Multiple WebF instance in same thread supported.
),
_kraken = WebF(
  bundle: WebFBundle.fromUrl('assets:assets/bundle.html'),
  runningThread: threadGroup.slave(), // Executes multiple JavaScript contexts in a single thread.
),
WebF(
  bundle: WebFBundle.fromUrl('assets:assets/bundle.html'),
  runningThread: threadGroup.slave(), //  Executes multiple JavaScript contexts in a single thread.
),

Design Graph:

image

performance comparison:

Test devices: Moto Qingyou XT1799 arch: arm

Test code:

p.addEventListener('click', (e) => {
  e.data = { name: 1};
}, true);

p.addEventListener('click', (e) => {
  console.log(e.data);
}, false);
image

@andycall andycall force-pushed the feat/feat/dedicated_js_thread_v2 branch from fd15f34 to b74961b Compare November 15, 2023 15:03
@andycall andycall force-pushed the feat/feat/dedicated_js_thread_v2 branch from d504f8f to 47d0ef9 Compare November 21, 2023 16:56
@andycall andycall force-pushed the feat/feat/dedicated_js_thread_v2 branch 7 times, most recently from 38bb28b to 32d60f4 Compare November 29, 2023 12:19
@andycall andycall changed the title [WIP] feat: add dedicated JavaScript thread support feat: add dedicated JavaScript thread support Nov 29, 2023
@andycall andycall force-pushed the feat/feat/dedicated_js_thread_v2 branch 4 times, most recently from 776fd4f to 4cf7c07 Compare December 1, 2023 08:35
@andycall andycall added the enhancement New feature or request label Dec 1, 2023
@andycall andycall self-assigned this Dec 1, 2023
@andycall andycall force-pushed the feat/feat/dedicated_js_thread_v2 branch from 0b217a3 to f2adf57 Compare December 2, 2023 06:29
@andycall andycall force-pushed the feat/feat/dedicated_js_thread_v2 branch 4 times, most recently from 7e4d14b to b841321 Compare December 17, 2023 16:31
@andycall andycall force-pushed the feat/feat/dedicated_js_thread_v2 branch 5 times, most recently from 3db0328 to 4dbfca3 Compare December 27, 2023 08:35
@andycall andycall force-pushed the feat/feat/dedicated_js_thread_v2 branch from 1ecfb58 to 79dc274 Compare December 28, 2023 07:52
@andycall andycall added this pull request to the merge queue Dec 28, 2023
Merged via the queue into main with commit 4286354 Dec 28, 2023
@andycall andycall deleted the feat/feat/dedicated_js_thread_v2 branch December 28, 2023 08:46
andycall added a commit that referenced this pull request Aug 12, 2024
Prior to WebF 0.16.0 "[Add Dedicated Threading
support.](#512)", the JSRuntime
lifecycle was managed by the DartIsolateContext lifecycle.


![ui_thread](https://github.com/user-attachments/assets/8e211366-eecd-4326-87e9-98ced7a34938)

But in Dedicated threads, the JSRuntime life cycle must be managed by
the WebFPage life cycle, and the `runtime_` redundancy created in
DartIsolateContext.

Therefore, JSRuntime lifetime managed by WebFPage lifetime in UI thread
mode is more uniform



![page_lifetime](https://github.com/user-attachments/assets/d5ea64e6-feca-40b5-9504-68fb1e245633)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

4 participants