javascript - Need help understanding performance of native promises versus Blubird -


background:

  1. i writing meteor app populates db data retrieved via soap requests made api end point on server somewhere.
  2. the initial request search via search term select. list of id's records match search.
  3. then make api request, time, each of records store own db (only selected values, not data)
  4. if have list of search terms above performed each of these.
  5. to avoid 'callback hell' , because though opportunity learn new opted use promises ordered sequentially: goes this: foreach searchterm -> gettheresults.then.foreachresult->fetchrecord
  6. for short sequences of 100 or worked fine when got 1000 hang. after speaking uncle google, came across threads native promises not being optimized in way , third party libraries faster. decided try bluebird, before doing test assertion might make things faster.

code code below creates sequence of 'sleep promises'. idea swap out bluebird promise implementation , observe time test takes run on sequence 5000 promises long.

var promise = require("bluebird"); // comment out native implementation  function sleep(time) {     return new promise(function (resolve, reject) {         settimeout(function() {             // process.stdout.write(".");             resolve(true);         }, time);     }); } // function badly named, please ignore function nativepromisesequence(n) {     // dont know how first line works     const arr = array.apply(null, array(n)).map(function () {});     return arr.reduce(function(sequence, e, i, a) {         return sequence.then(function() {             return sleep(1);         });     }, promise.resolve()); } 

the test using 'chai-as-promised' testing promises.

it('run 5000 promises in chain', function() {             this.timeout(7000);             return nativepromisesequence(5000).should.eventually.equal(true);         }); 

the result on promise chain of 5000 test bluebird implementation completed second slower native promises

have made mistake here or missed something?


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -