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

Move Babel to web-worker #1346

Merged
merged 16 commits into from
Aug 27, 2017
Merged

Move Babel to web-worker #1346

merged 16 commits into from
Aug 27, 2017

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Aug 25, 2017

Resolves #1342

Perf Impact

Here's a super-unscientific example of processing a large UMD file while scrolling around the page.

Before

screen shot 2017-08-26 at 9 51 48 am

#### After

screen shot 2017-08-26 at 9 51 55 am

@bvaughn bvaughn changed the title Move babel to web worker Move Babel to web-worker [work in progress] Aug 25, 2017
@babel-bot
Copy link
Contributor

babel-bot commented Aug 25, 2017

Deploy preview ready!

Built with commit fde40ac

https://deploy-preview-1346--babel.netlify.com

@bvaughn
Copy link
Contributor Author

bvaughn commented Aug 26, 2017

After commit be69e4a I'm seeing a bit of weirdness with the env plug-in in a web-worker. When I pass it options, it errors with:

Options {...} passed to a preset which does not accept options.

But if I try to add the preset without options, it errors with:

Unknown option: foreign.availablePlugins. Check out http://babeljs.io/docs/usage/options/ for more information about options.

A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:

Invalid:
{ presets: [{option: value}] }
Valid:
{ presets: [['presetName', {option: value}]] }

This isn't quite working yet but I'm going to commit to share with others.
@vjeux
Copy link

vjeux commented Aug 26, 2017

@azz moved prettier to a worker on the playground and it worked really well btw :)

@bvaughn
Copy link
Contributor Author

bvaughn commented Aug 26, 2017

Nice! 😄

I'd love to do it for Flow too, after this lands. That's the most painful REPL in terms of locking the UI.

import compile from "./compile";
import registerPromiseWorker from "promise-worker/register";

declare var Babel: any;
Copy link
Member

Choose a reason for hiding this comment

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

Do webpack externals not work in a web worker? require('babel-standalone') should be the same as referencing the global Babel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm. Babel (or babel-standalone) isn't one of the things we alias though, is it?

Copy link
Member

Choose a reason for hiding this comment

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

Oh good catch, we don't alias it because it's lazy loaded. Sorry for the confusion @bvaughn :D

@@ -39,13 +48,12 @@ export default function loadBabel(
return;
}

let version = config.version;
Copy link
Member

Choose a reason for hiding this comment

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

I think the earlier position of this code was better, since the comment explains what this variable is for (config.version is passed in dev, which is mentioned in the comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't actually intend to move it. Have just been iterating on this code.

@Daniel15
Copy link
Member

Nice work!

case "compile":
return compile(message.code, message.config);

case "getBabelVersion":
Copy link
Member

Choose a reason for hiding this comment

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

Ooh, I should totally steal this idea rather than building a custom file

Copy link
Member

@xtuc xtuc left a comment

Choose a reason for hiding this comment

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

That's awesome, thanks!

@bvaughn bvaughn changed the title Move Babel to web-worker [work in progress] Move Babel to web-worker Aug 27, 2017
@bvaughn
Copy link
Contributor Author

bvaughn commented Aug 27, 2017

Thanks @xtuc!

Wrapped up the last thing this morning. This PR should be good to go!

I tested Chrome, Firefox, Safari, Edge, Brave on Android, and iOS Safari.

PS We have a layout issue on iOS Safari but that's not related to this PR.

…e for type clarity

Compile error must be a string now that we compile in a web-worker. (Errors can't be passed from worker to main.) Technically eval error could be an error object, but since we weren't using the stack anyway, I think consistency is nice for these two properties.
This is no longer needed since we're using the inline worker-loader
@bvaughn
Copy link
Contributor Author

bvaughn commented Aug 27, 2017

Thanks all for the feedback and reviews!

I made a couple of small tweaks and tidied up. As soon as CI finishes, I'm going to merge this. 😄

@bvaughn bvaughn merged commit 439d7e0 into master Aug 27, 2017
@bvaughn bvaughn deleted the move-babel-to-web-worker branch August 27, 2017 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants