Skip to content

Conversation

timfish
Copy link
Member

@timfish timfish commented Sep 15, 2025

No bundlers support resolving the wasm binary with the default code:

const path = require('path').join(__dirname, 'orchestrion_js_bg.wasm');
const bytes = require('fs').readFileSync(path);

That means if code gets bundled, the wasm is missing and this library cannot be used.

This PR inlines the wasm binary as a base64 string which works even if the code is bundled:

const bytes = Buffer.from('AGFzbQE...snip...', 'base64');

Downsides?

  • The binary (and therefore the module) is about 33% larger
  • Maybe less performant loading this way as it goes through the JavaScript parser?

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we exposed two exports? One that has the inline wasm, and one without. Then users can opt-in to inlining it.

@timfish
Copy link
Member Author

timfish commented Sep 17, 2025

What if we exposed two exports?

We can but @apm-js-collab/tracing-hooks would need to do the same.

It looks like it's quite common to inline wasm like this. It's a common webpack config:
https://github.com/search?q=%2F%5C.wasm%2F+AND+%2Fasset%5C%2Finline%2F&type=code

@timfish timfish merged commit 9da6297 into main Sep 17, 2025
1 check passed
@timfish timfish deleted the feat/inline-wasm-binary branch September 17, 2025 19:55
@timfish timfish mentioned this pull request Sep 17, 2025
timfish added a commit to apm-js-collab/tracing-hooks that referenced this pull request Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants