Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] JS API #77

Closed
multics opened this issue Apr 27, 2020 · 4 comments
Closed

[Feature] JS API #77

multics opened this issue Apr 27, 2020 · 4 comments

Comments

@multics
Copy link

multics commented Apr 27, 2020

I was trying to use esbuild with svelte. The procedure is like this:

  1. convert *.svelte to *.js
  2. esbuild entry.js to bundle.js

I am writing a transpiler to do these tasks.
Step 1 was achieved by using the API svelte.compile, but step 2 has to be achieved by using CLI: esbuild --bundle --outfile bundle.js entry.js.

I was hoping esbuild could provide an API so I can create the transpiler in a JavaScript file.

@evanw
Copy link
Owner

evanw commented Apr 29, 2020

I'm assuming you're intending for the API to be a thin wrapper around child_process.exec. That sounds like a great idea to me.

@kzc
Copy link
Contributor

kzc commented May 2, 2020

At least for the wasm case, wouldn't a wrapper around async function esbuildStartWorker be more performant in light of the overhead of exec'ing a process for each call?

@evanw
Copy link
Owner

evanw commented May 2, 2020

At least for the wasm case, wouldn't a wrapper around async function esbuildStartWorker be more performant in light of the overhead of exec'ing a process for each call?

No, unfortunately not. The WebAssembly build is around 10x slower than the native build. I assume it's at least some combination of being single-threaded, JIT warm-up, and the lack of a parallel GC. As the comment at the top of browser.js says, that file only exists to make it possible to run in the browser. It's not at all designed to be fast.

@kzc
Copy link
Contributor

kzc commented May 2, 2020

I'm surprised that wasm is 10X slower than native. I vaguely recall reading when it was announced that it was purported to be only 2X slower, although I could be mistaken.

I understand the initial JIT warm up is slow, but once that one-time cost is paid shouldn't all subsequent wasm esbuild invocations be considerably faster?

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

No branches or pull requests

3 participants