You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Electron中低延迟向渲染进程传输大YUV数据的方案咨询

跨进程传输6K视频YUV数据的性能优化问题

我正在开发一个视频相关项目,出于安全考虑已禁用nodeIntegration并启用contextIsolation。业务逻辑在utility process中处理,解码后的YUV数据需发送至renderer process,通过VideoFrame和canvas完成渲染。但处理6K分辨率视频时,YUV数据量极大,传输至渲染进程的耗时过长,无法达到30fps的目标帧率。设备配置为Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz。

性能测试代码

setInterval(()=> {
  const beforeAlloc = performance.now()
  const data = new Uint8Array(4000_0000)  // large array
  // const data = new Uint8Array(4000)
  const afterAlloc = performance.now()

  const beforeSend = performance.now()
  port.postMessage(data) // the port is MessageChannelMain.port
  const afterSend = performance.now()

  const now = performance.now()
  // alloc's time was almost negligible, while postMessage took more than 90% of the time
  console.log(`alloc: ${parseInt(afterAlloc - beforeAlloc)}, send: ${parseInt(afterSend - beforeSend)}, time since last: ${parseInt(now - lastTime)}`)
  lastTime = now
}, 1000 / 30)

测试结果

传输大数据时的输出

alloc: 0, send: 77, time since last: 77
alloc: 3, send: 76, time since last: 80
alloc: 3, send: 82, time since last: 85
alloc: 0, send: 84, time since last: 85
alloc: 3, send: 78, time since last: 82
alloc: 3, send: 95, time since last: 99
...

传输小数据时的输出

alloc: 0, send: 0, time since last: 46
alloc: 0, send: 0, time since last: 46
alloc: 0, send: 0, time since last: 46
alloc: 0, send: 0, time since last: 48
alloc: 0, send: 0, time since last: 46
alloc: 0, send: 0, time since last: 46
...

当前困境与疑问

为避免阻塞main process,我选择在utility process中处理逻辑并通过MessageChannelMain通信,但效率仍不理想。目前能想到的高效方案是启用nodeIntegration并关闭contextIsolation,让renderer process直接访问YUV数据,但非必要不想这么做。

想请教:

  • 是否有其他高效的跨进程大数据传输方法?
  • 我的实现思路是否存在问题?
  • 需要实时展示处理后的帧,还有其他解决方案吗?

内容的提问来源于stack exchange,提问作者li wakin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 11:49:58