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

react-packager: Use Bluebird (or others) instead of Q as Promises library #361

Closed
pilwon opened this issue Mar 27, 2015 · 13 comments
Closed
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@pilwon
Copy link
Contributor

pilwon commented Mar 27, 2015

Q is very slow and eats so much memory compared to alternative Promises libraries as shown here.

Consider switching to Bluebird or something else to squeeze out performance for react-packager.

@amasad
Copy link
Contributor

amasad commented Mar 27, 2015

I think most bottleneck are transformation and filesystem. If you want to give it a go and report back numbers, I'll happily consider it :)

@petkaantonov
Copy link

The benchmark isn't really relevant as it runs with N=10000 and (I assume) packager is always N=1 - if you run the benchmark with N=1 you will hopefully not see any difference between implementations as anything is fast for a small N.

@amasad
Copy link
Contributor

amasad commented Mar 28, 2015

Thanks for the clarification @petkaantonov
If we end up standardizing on Bluebird in React Native we'll switch the packager to it as well.

@amasad amasad closed this as completed Mar 28, 2015
@pilwon
Copy link
Contributor Author

pilwon commented Mar 30, 2015

@amasad @petkaantonov

I probably picked an irrelevant benchmark above depending on what it really tested, but I still think I identified a real performance bottleneck here...

I ran a quick test just on DependencyGraph and got an interesting result as follows:

Test Summary

Bluebird performed almost 2x faster 👊

  • System Info
  • MacBook Pro (Retina, 13-inch, Early 2015)
  • 2.7 GHz Intel Core i5
  • 16 GB 1867 MHz DDR3

You can find the test script and full result here.

DependencyGraph with Q (current code)

#ofRuns:  100
Average: 5016 ms
Median:  4879.5 ms
Minimum: 4079 ms
Maximum: 7744 ms
StdDev:  639.8 ms

DependencyGraph with Bluebird (modified code)

#ofRuns:  100
Average: 2742.3 ms
Median:  2648 ms
Minimum: 2043 ms
Maximum: 5034 ms
StdDev:  504.6 ms

Note that I only replaced DependencyGraph module for this quick test. Imagine how much performance gain you can expect if all modules currently using Q make a switch to Bluebird. There are even (presumably) faster (less features) promise implementations such as es6-promise.

I discovered this problem while trying to integrate with webpack. The solution I currently settled on uses DependencyGraph to query internal dependencies to be able to resolve react-native modules from the webpack land. Each webpack build took annoyingly too long, that's how I started searching for an internal bottleneck.

@petkaantonov
Copy link

That's surprising that so many promises are being created that there is actually a difference. It would be interesting to know how many. The bluebird sequential benchmark creates 80000 promises with N=10000 and 8 promises with N=1, hence why you wouldn't see any difference with N=1.

@pilwon
Copy link
Contributor Author

pilwon commented Mar 30, 2015

@petkaantonov This particular case (DependencyGraph) that I tested with hits the filesystem like crazy as it scans the entire file tree to extract dependencies information. The promises library is heavily utilized to glue IO and transformation operations.

What's the best way to measure how many promises are created?

@petkaantonov
Copy link

@pilwon In bluebird I have just ad hoc edited the promise constructor code by doing Promise.promisesCreated++ (Initialize it to 0 somewhere first) inside the constructor and then reading it out at the end of the benchmark.

Also results for 3.0 would be interesting too as it provides some significant performance improvements to Promise.all and promisify

@pilwon
Copy link
Contributor Author

pilwon commented Mar 30, 2015

@petkaantonov Is this the right place?

@petkaantonov
Copy link

@pilwon Yes it is

@pilwon
Copy link
Contributor Author

pilwon commented Mar 30, 2015

46039 promises are created in each test run. 😱 😲 😒

@petkaantonov
Copy link

Ok, that's shocking and my earlier point doesn't make sense any more.. I was expecting more like 10-100 promises being created

@amasad
Copy link
Contributor

amasad commented Mar 31, 2015

This awesome, thanks for digging into it.

@amasad amasad reopened this Mar 31, 2015
vjeux pushed a commit to vjeux/react-native that referenced this issue Apr 13, 2015
Summary:
This PR improves performance of `react-packager` by switching the promises library from the [Q](https://github.com/kriskowal/q) to [Bluebird](https://github.com/petkaantonov/bluebird).

[Here is the test result](facebook#361 (comment)) showing a noticeable difference. (2x speed improvement)

Please refer to [this issue](facebook#361) for more details.
Closes facebook#516
Github Author: Pilwon Huh <pilwon@gmail.com>

Test Plan:
./runJestTests
start app and click around
vjeux pushed a commit to vjeux/react-native that referenced this issue Apr 14, 2015
Summary:
This PR improves performance of `react-packager` by switching the promises library from the [Q](https://github.com/kriskowal/q) to [Bluebird](https://github.com/petkaantonov/bluebird).

[Here is the test result](facebook#361 (comment)) showing a noticeable difference. (2x speed improvement)

Please refer to [this issue](facebook#361) for more details.
Closes facebook#516
Github Author: Pilwon Huh <pilwon@gmail.com>

Test Plan:
./runJestTests
start app and click around
vjeux pushed a commit to vjeux/react-native that referenced this issue Apr 15, 2015
Summary:
This PR improves performance of `react-packager` by switching the promises library from the [Q](https://github.com/kriskowal/q) to [Bluebird](https://github.com/petkaantonov/bluebird).

[Here is the test result](facebook#361 (comment)) showing a noticeable difference. (2x speed improvement)

Please refer to [this issue](facebook#361) for more details.
Closes facebook#516
Github Author: Pilwon Huh <pilwon@gmail.com>

Test Plan:
./runJestTests
start app and click around
@amasad
Copy link
Contributor

amasad commented Apr 21, 2015

fixed

@amasad amasad closed this as completed Apr 21, 2015
cpojer pushed a commit to facebook/metro that referenced this issue Jan 26, 2017
Summary:
This PR improves performance of `react-packager` by switching the promises library from the [Q](https://github.com/kriskowal/q) to [Bluebird](https://github.com/petkaantonov/bluebird).

[Here is the test result](facebook/react-native#361 (comment)) showing a noticeable difference. (2x speed improvement)

Please refer to [this issue](facebook/react-native#361) for more details.
Closes facebook/react-native#516
Github Author: Pilwon Huh <pilwon@gmail.com>

Test Plan:
./runJestTests
start app and click around
@facebook facebook locked as resolved and limited conversation to collaborators May 29, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants