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

Use fast-async for async/await support #366

Closed
wants to merge 1 commit into from
Closed

Use fast-async for async/await support #366

wants to merge 1 commit into from

Conversation

timdorr
Copy link

@timdorr timdorr commented Aug 4, 2016

fast-async is based on nodent, a generator-optional implementation of async/await support.

By default, it does not use generators, which saves the usage of regenerator if generator functions are not otherwise used. It is also significantly faster, with order-of-magnitude perf gains on mobile browsers in particular.

It also smaller, reducing gzipped file size by 1.44KB in a simple test case:

File sizes after gzip:

  48.7 KB (+1.44 KB)  build/static/js/main.c60c74db.js
  289 B               build/static/css/main.9a0fe4f1.css

Test case code:

class App extends Component {
  async componentDidMount() {
    try {
      const response = await fetch('https://jsonplaceholder.typicode.com/posts/1');
      const data = await response.json();
      console.log(data);
    } catch (lol) {
      alert('oh noes')
    }
  }

  //...
}

I'm not an expert on this library, so there may be further gains to be had from better tuning. But on the surface, we're already getting a good bump on both speed and size.

fast-async is based on nodent, a generator-optional implementation of async/await support.
By default, it does not use generators, which saves the usage of regenerator if generator functions are not otherwise used.
It is also significantly faster, with order-of-magnitude perf gains on mobile browsers in particular.
It also reduces file size by 1.44KB in a simple test case.
@ghost ghost added the CLA Signed label Aug 4, 2016
@gaearon
Copy link
Contributor

gaearon commented Aug 4, 2016

reducing gzipped file size by 1.44KB in a simple test case:

I'm a bit confused, doesn't it say the opposite? (+ 1.44 KB)

@timdorr
Copy link
Author

timdorr commented Aug 4, 2016

Oh yeah, I ran it backwards. Previous was with fast-async. Current was with babel-plugin-syntax-async-functions.

@gaearon
Copy link
Contributor

gaearon commented Aug 4, 2016

I think I'll be happy to take this if it proves to be very solid. For now issues like MatAtBread/fast-async#8 mean quite a lot more test coverage is required before this can go.

We also try to use the transforms we use at Facebook to ensure quality. So maybe this could be contributed to Babel and start a discussion there?

@timdorr
Copy link
Author

timdorr commented Aug 5, 2016

That's up to @MatAtBread, who appears to be on break according to that PR.

It looks like nodent does it's own code parsing (with Acorn), so as long as that could be converted to something running Babylon, it's certainly possible. It would definitely be an interesting change to Babel's async plugin.

Sounds like that's more of an issue for upstream in Babel, so I'll close this PR out.

@timdorr timdorr closed this Aug 5, 2016
@timdorr timdorr deleted the fast-async branch August 5, 2016 02:42
@MatAtBread
Copy link

@timdorr, actually, fast-async uses Babel/Babylon for parsing (since it's a Babel plugin), whereas nodent is the stand-alone compiler. I hope to get back to the issues next week when I'm back from my holidays

@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants