webassembly-loader icon indicating copy to clipboard operation
webassembly-loader copied to clipboard

feat: add `useJSONParse` option

Open adroitwhiz opened this issue 4 years ago • 0 comments

This PR contains a:

  • [ ] bugfix
  • [x] new feature
  • [x] code refactor
  • [x] test update
  • [ ] typo fix
  • [x] documentations
  • [ ] metadata update

Motivation / Use-Case

Currently, the buffer of WASM code is stored in the generated JS bundle as an array, e.g:

Buffer.from([0,97,115,109...])

This means that browsers, and any Webpack plugins that attempt to parse the generated code (e.g. minifiers), will have to individually parse every array element.

This PR adds the useJSONParse configuration option, which stringifies this array and wraps it in a JSON.parse call, like so:

Buffer.from(JSON.parse('[0,97,115,109...]'))

This massively improved the compilation speed of my project, and may have performance benefits for browsers as well.

Breaking Changes

N/A

Additional Info

I also refactored the code a bit--in particular, wrapper.ts no longer returns one string per configuration type, and instead returns functions that return those strings. This means that instead of 6 strings being created per compile, only 1 is.

adroitwhiz avatar Mar 22 '20 03:03 adroitwhiz