V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
shawncheung
V2EX  ›  Node.js

protobuf.js 中的 encode 与 decode 模块使用 wasm 模块代替

  •  
  •   shawncheung · 2021-02-23 20:34:34 +08:00 · 2222 次点击
    这是一个创建于 1149 天前的主题,其中的信息可能已经有所发展或是发生改变。

    看了很多关于 wasm 的相关资料,这里 wasm 的性能数据还是不错的,这里有没有可能让 protobuf.js 里面的编解码部分使用 wasm 来代替从而进一步提升 node 在 pb 解析的性能呢?有小伙伴做过尝试吗?

    4 条回复    2021-02-24 11:38:41 +08:00
    learningman
        1
    learningman  
       2021-02-23 21:27:50 +08:00 via Android
    你说的是 wasm 还是 asm.js ,如果是后者感觉不是很有必要
    jones2000
        2
    jones2000  
       2021-02-24 00:08:13 +08:00
    用 protobuf c++版本, 做压缩 /解压 2 个接口,, 根据 WebAssembly 教程里面编译下就可以用了。https://developer.mozilla.org/en-US/docs/WebAssembly
    whitehack
        3
    whitehack  
       2021-02-24 10:24:38 +08:00
    首先 wasm 肯定没有 c++ 效率高, wasm 的代价也是不低的.

    回到 protobuf,
    node 里有一个 c++实现的包 https://github.com/chrisdew/protobuf

    记得我做过性能测试对比,c++的实现是比 js 实现高很多的.

    但是 chrisdew/protobuf 有点不兼容 protobufjs,如果你原来就用的 protobufjs 的话, 可以参考我几年前改过的 https://github.com/whtiehack/protobuf

    另外这是几年前的老库了.
    bertonzh
        4
    bertonzh  
       2021-02-24 11:38:41 +08:00
    你要考虑 JS 和 WASM 之间交互数据的开销,不能只对比编解码。交互数据的过程实际上就是编解码的过程。
    如果是给 Node 使用,可以考虑 NAPI 。WebAssembly 就算了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5847 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 06:22 · PVG 14:22 · LAX 23:22 · JFK 02:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.