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 request] Consideration of using async / await #3328

Open
segayuu opened this issue Nov 5, 2018 · 8 comments
Open

[feature request] Consideration of using async / await #3328

segayuu opened this issue Nov 5, 2018 · 8 comments

Comments

@segayuu
Copy link
Contributor

segayuu commented Nov 5, 2018

For feature request

The native promise after node v10 is fast enough.
Since async / await is supported in node v7 or later, it can be used when support of node v6 LTS (maintenance) is turned off.
Using async / await tends to make the code simple, and sequential asynchronous is faster than bluebird on the bluebird side benchmark (in the case of parallel, now bluebird is faster).

@NoahDragon
Copy link
Member

Agree. Performance is always the key improvement for Hexo. IMHO, this is not a feature, more like an enhancement. Anyway, thanks for bringing this up.

@yoshinorin
Copy link
Member

yoshinorin commented Nov 5, 2018

I agree. Same as other hexo repositories.
IMO we can drop node v6 support after 2019 Apr.

@curbengh
Copy link
Contributor

curbengh commented Dec 14, 2019

Just started working on this. A few observations:

  • Bluebird.asCallback is to support callback style. Most Some Hexo API supports callback, so this can't be dropped for a foreseeable future.
  • Promise.finally is only supported in Node 10.3+, so need to wait until Node 8 is dropped.

@SukkaW
Copy link
Member

SukkaW commented Dec 16, 2019

https://blog.kuzzle.io/bluebird-vs-native-vs-async/await-state-of-promises-performances-in-2019

TL;DR:
In Node.js 10, it is impossible to do without Bluebird in critical code areas given the performance of its promises compared to native promises and async/await.
In Node.js 12, the performance of async/await is comparable to that of Bluebird, so we can use async/await throughout Kuzzle core.

And according to the hexo's benchmark from some related PR, currently I see no performance gained through replacing bluebird with async / await.

@curbengh
Copy link
Contributor

The benchmark linked by OP only shows async/await being slightly faster than bluebird (in sequential), the difference looks to be within margin of error.

I still believe bluebird is faster currently and for a foreseeable future; even our benchmark doesn't show it's faster in Node 13. Perhaps there may be bottleneck somewhere that either approach (bluebird/native) doesn't make any difference.

At the same time, async/await is significantly more readable, so if the perf is not affected, let's use it. especially for unit tests, where perf doesn't matter much.

@dailyrandomphoto
Copy link
Member

* [`Bluebird.asCallback`] is to support callback style. Most Hexo API supports callback, so this can't be dropped for a foreseeable future.

How about deprecating asCallback in the internal APIs first? Without asCallback, the code will be more readable and simple.

- View.prototype.render = function(options, callback) {
+ View.prototype.render = function(options) {
- if (!callback && typeof options === 'function') {
-    callback = options;
-    options = {};
-  }

  options = options || {};

And I found only a few examples of using callbacks as asynchronous at https://hexo.io/api/.
Maybe we can drop all asCallback at the next major release.

@SukkaW
Copy link
Member

SukkaW commented Jul 31, 2020

https://blog.kuzzle.io/bluebird-vs-native-vs-async/await-state-of-promises-performances-in-2019

TL;DR:
In Node.js 10, it is impossible to do without Bluebird in critical code areas given the performance of its promises compared to native promises and async/await.
In Node.js 12, the performance of async/await is comparable to that of Bluebird, so we can use async/await throughout Kuzzle core.

And according to the hexo's benchmark from some related PR, currently I see no performance gained through replacing bluebird with async / await.

Here we are, 2020's benchmark: https://blog.kuzzle.io/bluebird-native-async_await-javascript-promises-performances-2020

Performance of sequential promises

Performance of parallel promises

Also, there goes the interesting discussion: nodejs/node#33384


TL, DR

Bluebird appears to be consistently faster.

@stevenjoezhang
Copy link
Member

As of 2024, Bluebird still holds a significant performance advantage in benchmarks. However, the actual performance gap in real-world applications like Hexo still needs further experimentation.

截屏2024-04-27 00 58 26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants