sidorares / sidorares/node-mysql2

WebAssembly based parser

Open
#335 12 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement performance
Dominant language
TypeScript
Stars
4.4k
Forks
680
Avg merge
9h 7m
Merged PRs (30d)
59

Description

Web assembly is already available ( behind flag ) in node 6, so might worth trying it as a next level of "Userspace JIT" approach

Some overview:
https://ia601503.us.archive.org/32/items/vmss16/titzer.pdf

Working wasm examples ( run with node --expose-wasm):

function fib(stdlib, foreign, heap) {
  "use asm";

  var i32 = new stdlib.Int32Array(heap);
  var f64 = new stdlib.Float64Array(heap);
  var imul = stdlib.Math.imul;

  function fib(n) {
    n = n|0;
    if (n >>> 0 < 3) {
      return 1|0;
    }
    return (fib((n-1)|0) + fib((n-2)|0))|0;
  }

  return {
    fib:fib
  };
}

var m = _WASMEXP_.instantiateModuleFromAsm(fib.toString());
var asmFib = m.fib;

var n = 38;
console.time("ASM:fib(" + n + ")");
var f = asmFib(n, global);
console.log(f);
console.timeEnd("ASM:fib(" + n + ")");

binary wasm:

https://gist.github.com/sidorares/90607f73b499f2ccb7dd908a080ebe5d

Problems:

  • no objects or strings in output. The only possible way I see now: generate json representation on the heap and use JSON.parse. Might still be fast! ( JSON.parse is very fast and often surpass manual object creation in speed )
  • quite a lot of work for a unknown performance gain

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/compile_text_parser.js and the linked WebAssembly examples, then review the binary wasm gist and Node's --expose-wasm behavior. Compare a wasm-based parser with the current userspace JIT approach, especially how results cross the no-objects-or-strings boundary. Done requires an integrated parser and evidence that its performance gain justifies the added work.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, wasm
Domain
backend, databases, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.