stream.Transform.push скорость
#nodejs #gulp #plugin.
Сссти ) Не часто пишу на javascript-e. Задачу реализовал, но скорость не нравится. Вопрос уперся в stream.Transform.push . Код var fs = require("fs"), through2 = require("through2"), Transform = require("stream").Transform, vinyl = require("vinyl"), async = require("async"); . . . resolveDependant = function(file, stream, cb){ /** * @var array tree - list of files[], aka driectory tree */ var reg = new RegExp("Catch me!", "gm"), seriesList = []; //for threading for(var f in tree){ seriesList.push( //игнорим function(file){ //игнорим return function(callback){ //игнорим fs.readFile(file, { encoding : "utf8" }, function(err, data){ //игнорим if(reg.exec(data)){ //trying to catch him! stream.push( //ТУТ теряется время! На 4 файла 1.6с. new vinyl({ //без предыдущей строчки: 0.4с для 4 файлов path : file, contents : new Buffer(data) }) ); } callback(); }); } }(tree[f]) ); } . . . this.chain = function() { //gulp.pipe(obj.chain()) call return through2.obj(function (file, enconding, cb) { /** * @var array tree - list of files[], aka driectory tree */ if(!tree.length) //just ensure that chain was called after initialization return cb(null, file); var stream = this; resolveDependant(file.path, stream, function(){ stream.push(file); //test mode ignore any input cb(); //return control to pipe }); }); } Поясните почему тут так печально stream.push( //ТУТ теряется время на 4 файла 1.6с. Ссылка, книги, советы - всему буду раз |
Часовой пояс GMT +3, время: 03:37. |