Skip to content

perf(platform/wasm): remove useless build flags#45

Merged
cloudwu merged 1 commit intocloudwu:masterfrom
yuchanns:improve/platform-wasm
Oct 23, 2025
Merged

perf(platform/wasm): remove useless build flags#45
cloudwu merged 1 commit intocloudwu:masterfrom
yuchanns:improve/platform-wasm

Conversation

@yuchanns
Copy link
Contributor

@yuchanns yuchanns commented Oct 23, 2025

  • 移除了之前开发过程中临时设置后来后来用不上的一些编译 flags (e.g. 支持 webgl2, 离屏渲染), 可以减少30k左右的体积。
  • 将预创建的 worker 数量改为根据用户的实际核心数设置,当用户浏览器核心数较少时,则设置为2避免卡死(如果 soluna 后续新增 bind service 则需要根据 bind serivce 数量增加最低值)

PS: 我今天尝试为 ltask 添加原生 WASM 多线程 API支持, 即 WASM Worker, 结果失败了。原因在于: WASM Worker 的启动总是异步的, 需要主线程让出事件循环后才会启动。而 WASM 在执行过程中不会让出,如果要实现这个功能,让 soluna 运行过程中让出, 会比较麻烦; 并且理论上需要在 thread_start 启动之后立即让出,否则 boot.mainthread_wait 会死锁。这个异步启动方式在写 js 代码时应该显得比较自然, 但是从 wasm 角度来看挺别扭的。

如果我的理解没有错的话 pthread 在 emscripten 的实现实际上也是基于一些预先创建的 wasm worker

通过 emscripten 官方文档对比 pthread 和 wasm worker, 我认为除了体积较小外, wasm worker 没什么特别的优势。FYI: https://emscripten.org/docs/api_reference/wasm_workers.html#pthreads-vs-wasm-workers-which-one-to-use

@yuchanns yuchanns force-pushed the improve/platform-wasm branch from 62a53c1 to 0c9a1c6 Compare October 23, 2025 07:35
@yuchanns yuchanns force-pushed the improve/platform-wasm branch from 0c9a1c6 to 6d69671 Compare October 23, 2025 07:37
@cloudwu cloudwu merged commit c02faee into cloudwu:master Oct 23, 2025
5 checks passed
@yuchanns yuchanns deleted the improve/platform-wasm branch October 23, 2025 07:44
@cloudwu
Copy link
Owner

cloudwu commented Oct 23, 2025

如果只是启动,是不是应该把启动线程和让工作线程分成两个步骤就可以?

比如先把 worker 都启动起来,但不工作。然后从主线程发起启动信号?

@yuchanns
Copy link
Contributor Author

想了下是可以。比如在 app init 里创建线程,然后在 frame callback 里等待 worker 启动,接着执行。

@cloudwu
Copy link
Owner

cloudwu commented Oct 23, 2025

我下周试试。在 init callback 应该就可以了

cloudwu added a commit that referenced this pull request Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants