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

Migrate to promises once they're optimized enough #71

Closed
chjj opened this issue Sep 21, 2016 · 5 comments
Closed

Migrate to promises once they're optimized enough #71

chjj opened this issue Sep 21, 2016 · 5 comments
Labels
enhancement Improving a current feature

Comments

@chjj
Copy link
Member

chjj commented Sep 21, 2016

The generators branch is a rewrite of bcoin using promises and generators: https://github.com/bcoin-org/bcoin/tree/generators

Unfortunately, promises and generators are slow and use a lot of memory when compared to callbacks (initial sync: 1ms block processing time vs 400 usec block processing time, 160-200mb heap size vs 75mb heap size, high watermark of 110mb heapused vs 50mb heapused).

Once async/await becomes ubiquitous, I see bcoin switching to that, but only if it is well optimized.

If anyone can optimize the generators branch, I'd be willing to switch now.

@chjj chjj added the enhancement Improving a current feature label Sep 21, 2016
@chjj
Copy link
Member Author

chjj commented Sep 21, 2016

Putting out a 1BTC bounty to anyone who can optimize the generators branch, such that it is near or less than 100mb heapsize during the initial checkpoints sync from a fast node (should always have 500 pending blocks after a getblocks).

@bpdavenport
Copy link

Have you tried using bluebird instead of native promises? See http://programmers.stackexchange.com/questions/278778/why-are-native-es6-promises-slower-and-more-memory-intensive-than-bluebird Replace spawn with Promise.coroutine (bluebird method)

@chjj
Copy link
Member Author

chjj commented Sep 22, 2016

I've tried using bluebird instead of native es6 promises. I didn't see a substantial difference in perf or memory usage. They seemed roughly the same. I'm starting to suspect generators and the state v8 has to hold along with them are the actual bottleneck here. Unfortunately generator functions can't be reimplemented externally. That being said, I haven't tried bluebird's coroutine method. I'll check that out.

I'm hoping I just used some kind of anti pattern here that I'm not aware of in my use of generators.

@chjj
Copy link
Member Author

chjj commented Sep 22, 2016

@bpdavenport You've earned yourself 1btc. Bluebird was exactly where I needed to look. I knew there was some kind of antipattern I was doing. Bluebird's convention is to define the function as obj.prototype.method = Promise.coroutine(function *() { code; }; where as I was calling spawn inside every method instead. Memory usage is excellent now.

You can post an address here. I'd say email it to me, but I don't have your gpg key (a quick keybase search yielded nothing), and I have nothing else to verify your identity on any other platform.

@chjj
Copy link
Member Author

chjj commented Sep 22, 2016

@bpdavenport shot an email your way. Closing now.

@chjj chjj closed this as completed Sep 22, 2016
@bucko13 bucko13 added the enhancement Improving a current feature label Apr 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improving a current feature
Projects
None yet
Development

No branches or pull requests

3 participants