Reduce cache size

Hopefully, this will help determine if the cache is the cause of the memory
growth we see.
This commit is contained in:
Thaddee Tyl 2015-09-21 14:21:44 +02:00
parent 5f475f107b
commit cb23cf2d76
2 changed files with 7 additions and 4 deletions

View File

@ -11,6 +11,7 @@ function Cache(size, type) {
type = type || 'unit';
this.size = size;
this.type = typeEnum[type];
if (this.type === typeEnum.unit) { this.size -= 1; }
// `cache` contains {content, index}.
// - content: the actual data that is cached.
// - index: the position in `order` of the data.
@ -30,6 +31,7 @@ Cache.prototype = {
// If the cache is full, remove the oldest data
// (ie, the data requested longest ago.)
var numberToRemove = this.limitReached();
if (numberToRemove > this.order.length) { numberToRemove = this.order.length; }
for (var i = 0; i < numberToRemove; i++) {
// Remove `order`'s oldest element, the first.
delete this.cache[this.order[0]];
@ -39,7 +41,7 @@ Cache.prototype = {
this.cache[cacheIndex] = {
index: this.order.length,
content: cached,
}
};
this.order.push(cacheIndex);
}
},
@ -58,9 +60,10 @@ Cache.prototype = {
return this.cache[cacheIndex] !== undefined;
},
// Returns true if we're past the limit.
// Returns the number of elements to remove if we're past the limit.
limitReached: function heuristic() {
if (this.type === typeEnum.unit) {
// Remove the excess.
return Math.max(0, (this.order.length - this.size));
} else if (this.type === typeEnum.heap) {
if (getHeapSize() >= this.size) {

View File

@ -157,8 +157,8 @@ var minAccuracy = 0.75;
// = 1 - max(1, df) / rf
var freqRatioMax = 1 - minAccuracy;
// Request cache size of 500MB (~1000 bytes/image).
var requestCache = new LruCache(500000);
// Request cache size of 50MB (~5000 bytes/image).
var requestCache = new LruCache(10000);
// Deep error handling for vendor hooks.
var vendorDomain = domain.create();