shawncheung
V2EX  ›  Node.js

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

  •  
  •   shawncheung · Feb 23, 2021 · 3201 views
    This topic created in 1905 days ago, the information mentioned may be changed or developed.

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

    4 replies    2021-02-24 11:38:41 +08:00
    learningman
        1
    learningman  
       Feb 23, 2021 via Android
    你说的是 wasm 还是 asm.js ,如果是后者感觉不是很有必要
    jones2000
        2
    jones2000  
       Feb 24, 2021
    用 protobuf c++版本, 做压缩 /解压 2 个接口,, 根据 WebAssembly 教程里面编译下就可以用了。https://developer.mozilla.org/en-US/docs/WebAssembly
    whitehack
        3
    whitehack  
       Feb 24, 2021
    首先 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  
       Feb 24, 2021
    你要考虑 JS 和 WASM 之间交互数据的开销,不能只对比编解码。交互数据的过程实际上就是编解码的过程。
    如果是给 Node 使用,可以考虑 NAPI 。WebAssembly 就算了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5530 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 56ms · UTC 07:43 · PVG 15:43 · LAX 00:43 · JFK 03:43
    ♥ Do have faith in what you're doing.