Giter VIP home page Giter VIP logo

Comments (18)

ysmood avatar ysmood commented on July 16, 2024 1

Of cause the closure of callback should be pre-allocated and cached, or it's not fair. I don't like the code of the benchmark, it's obscure and not clear for people to reason about what it really does.

from yaku.

ysmood avatar ysmood commented on July 16, 2024

I'm working on it, I will make PR to add Yaku to the benchmark list later.

from yaku.

benjamingr avatar benjamingr commented on July 16, 2024

Thanks, please keep me updated.

from yaku.

ysmood avatar ysmood commented on July 16, 2024

@benjamingr The benchmark of bluebird is strange:

file                   time(ms)  memory(MB)
promises-bluebird.js        393      111.57
callbacks-baseline.js       519       37.93

Darwin 15.0.0 x64
Node.JS 4.0.0
V8 4.5.103.30
Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz × 8

It's faster than the raw callback, it's impossible! I suspect the benchmark is not properly designed, I can't trust it before I find an explain.

from yaku.

benjamingr avatar benjamingr commented on July 16, 2024

That makes sense, allocating a promise is cheaper than allocating a closure. You're very welcome to read the tests yourself and see. For example:

doOne(function(err, data){  if(err) return cb(err);
  doTwo(data, function(err, data2){  if(err) return cb(err);
      doThree(data2, function(err, data3){ if(err) return cb(err);
            cb(null, data3.foo);
       });
   });
});

Vs - doOne.then(doTwo).then(doThree) with regards to closures and allocations required.

What is possible is that the callbacks code can be sped up. Some work went into that by some people - but by all means - a PR would be appreciated.

from yaku.

ysmood avatar ysmood commented on July 16, 2024

@benjamingr I haven't done much optimization, but yaku is pretty good for now:

file                                     time(ms)  memory(MB)
callbacks-baseline.js                         167       32.50
promises-bluebird-generator.js                226       33.71
promises-bluebird.js                          310       44.93
promises-tildeio-rsvp.js                      348       70.52
promises-cujojs-when.js                       380       67.51
callbacks-caolan-async-waterfall.js           497       77.46
promises-yaku.js                              530       94.87
promises-lvivski-davy.js                      600      125.66
promises-dfilatov-vow.js                      698      141.27
promises-calvinmetcalf-lie.js                 832      150.71
generators-tj-co.js                           889      143.92
promises-ecmascript6-native.js                918      194.81
promises-obvious-kew.js                      1131      237.62
promises-then-promise.js                     1529      214.70
promises-medikoo-deferred.js                 1857      157.93
observables-Reactive-Extensions-RxJS.js      2831      283.23
observables-pozadi-kefir.js                  3287      164.02
promises-kriskowal-q.js                     12506      829.64
observables-baconjs-bacon.js.js             18895      828.93
observables-caolan-highland.js              30631      530.52

Platform info:
Darwin 15.0.0 x64
Node.JS 4.0.0
V8 4.5.103.30
Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz × 8

from yaku.

benjamingr avatar benjamingr commented on July 16, 2024

Ping @spion

from yaku.

ysmood avatar ysmood commented on July 16, 2024

@benjamingr You can run it yourself, I forked bluebird: https://github.com/ysmood/bluebird/commit/826d2262c4b9c746a1fdb362819b0a444b9612d2

from yaku.

spion avatar spion commented on July 16, 2024

@benjamingr yes?

from yaku.

benjamingr avatar benjamingr commented on July 16, 2024

Well, the benchmarks were being criticized, thought you might want to address that

On 12 Oct 2015, at 21:02, Gorgi Kosev [email protected] wrote:

@benjamingr yes?


Reply to this email directly or view it on GitHub.

from yaku.

spion avatar spion commented on July 16, 2024

Ah.

To be honest I've never seen callbacks run slower than (generatorless) promises in that benchmark. Sounds like V8 might've decided to bail out on optimising some function on that particular run for some reason.

Regarding the way the benchmark is written, it could indeed use some refactoring. Regarding the way the callback code is written, thats only the baseline in bluebird's fork - there are many more variants in the original

from yaku.

ysmood avatar ysmood commented on July 16, 2024

@benjamingr I did some optimization, now Yaku is much better.

$ ./bench doxbee 

results for 10000 parallel executions, 1 ms per I/O op

file                                     time(ms)  memory(MB)
callbacks-baseline.js                         176       32.39
promises-bluebird-generator.js                192       34.05
promises-bluebird.js                          268       45.48
promises-cujojs-when.js                       373       67.90
*promises-yaku.js                             403       84.05
promises-tildeio-rsvp.js                      405       69.21
callbacks-caolan-async-waterfall.js           562       77.51
promises-lvivski-davy.js                      568      125.35
promises-dfilatov-vow.js                      640      140.65
promises-calvinmetcalf-lie.js                 693      150.50
promises-ecmascript6-native.js                825      188.38
generators-tj-co.js                          1077      140.99
promises-obvious-kew.js                      1298      266.98
promises-then-promise.js                     1439      201.00
promises-medikoo-deferred.js                 2142      264.46
observables-pozadi-kefir.js                  2624      164.00
observables-Reactive-Extensions-RxJS.js      3268      283.15
promises-kriskowal-q.js                     15118      871.54
observables-baconjs-bacon.js.js             20351      854.80
observables-caolan-highland.js              27834      528.66

Platform info:
Darwin 15.0.0 x64
Node.JS 4.2.1
V8 4.5.103.35
Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz × 8

from yaku.

benjamingr avatar benjamingr commented on July 16, 2024

This is getting there! 1/2 the speed and 1/3 the memory usage of bluebird is very nice :) I still think there is room to go though. Definitely better than what core-js currently uses - if the API is compatible I'm for it :)

from yaku.

winterland1989 avatar winterland1989 commented on July 16, 2024

Can you give me some credits on b336a4d please : )
I thought this is basically the idea when i show you in my Action.js, and by the way, i give part of the original credits to bluebird in the code comment. since it's bluebird's hilarious new Function based solution inspired me. Thank you.

from yaku.

ysmood avatar ysmood commented on July 16, 2024

@winterland1989 Very sorry for that, I meant to credit you when I finished all the optimization include the Promise.all, this post is just a beginning.

This trick is used by Action.js and many other libs like ramda:
https://github.com/ramda/ramda/blob/c6138eed1c57dca717c73bc656c7dcabc220ed92/src/internal/_curry3.js#L16

curry: https://github.com/dominictarr/curry/blob/11b4be8f092123ae7fc2df526ae9cac52f6feae7/curry.js#L12

But I don't think we should mention things like that everyday, because ramda and many other libs are already using this trick before, everybody knows it. But if you insist, I will be very sorry about that.

Like I told you the try catch trick, you don't have to tell everybody you are inspired by the bluebird, everybody is using it, they don't have to credit bluebird.

from yaku.

winterland1989 avatar winterland1989 commented on July 16, 2024

OK, thanks for explanations, and i'd like keep communicate with you on Promise.all stuff, i'm wrapping my head on it now : )

from yaku.

ysmood avatar ysmood commented on July 16, 2024

@winterland1989 Looking forward your breaking through on the Promise.all :D

from yaku.

winterland1989 avatar winterland1989 commented on July 16, 2024

One thing to be noted that, this trick which try to cover some cases when arguments is less than given point cause way too much memory allocation, you can measure it by print system memory usage before Promise.all and after the promise array are built in the benchmark, at that given point, bluebird still use memory as low as possible, so i believe our trick is somehow inferior than new Function based solution. I'll keep you notified when i test it more.

from yaku.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.