Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions lib/dynamic-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
var fs = require('fs');

function objectValues(obj) {
if (typeof obj !== 'object') {
return [];
var values = [];
if (typeof obj === 'object') {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
values.push(obj[key]);
}
}
}

return Object.keys(obj).map(function (key) {
return obj[key];
});
return values
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? Your code is functionally identical to the shorter, simpler code that was there before?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The performance was pretty bad so I tried to improve it. But you're right this probably doesn't change much.


module.exports = DynamicCache;
Expand All @@ -35,15 +37,31 @@ DynamicCache.prototype.update = function (cb) {
this._queue = [];
}
}.bind(this);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug in this is actually just that it double counts things, leading to circular structures creating an infinite loop.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that was definitely one problem.
But the whole map, reduce, concat made it also pretty slow.
My version is much faster in our setup

var getDeps = function (filename) {
if (this._files[filename]) {
return [[filename]].concat(this._files[filename].map(getDeps)).reduce(function (a, b) {
return a.concat(b);
});
} else {
return [filename];
var dependencies = this._files[filename];
var dependenciesSet = {};

dependenciesSet[filename] = true;

var getSubDeps = function(deps){
deps.forEach(function (dep, index) {
if (!dependenciesSet[dep]) {
dependenciesSet[dep] = true;
var subDeps = this._files[deps[index]];
if (subDeps){
getSubDeps(subDeps);
}
}
}, this);
}.bind(this)

if (dependencies) {
getSubDeps(dependencies);
}
return Object.keys(dependenciesSet);
}.bind(this);

files.forEach(function (filename) {
fs.stat(filename, function (err, stats) {
if (err || stats.mtime.getTime() !== this._time[filename]) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"require-test": "1.0.0"
},
"dependencies": {
"browserify": "^8.1.3",
"browserify": "^9.0.8",
"mold-source-map": "0.3.0",
"ms": "^0.7.0",
"once": "^1.3.1",
"prepare-response": "^1.1.2",
"uglify-js": "^2.4.16"
}
}
}