Remove 2nd level cache

This commit is contained in:
Dávid Szabó 2016-08-24 23:09:36 +02:00 committed by Julian Descottes
parent 6ee23e22df
commit 0bbb4ff2d5
2 changed files with 17 additions and 11 deletions

View File

@ -32,18 +32,19 @@
processedFrame = cache[key1]; processedFrame = cache[key1];
} else if (frame instanceof pskl.model.frame.RenderedFrame) { } else if (frame instanceof pskl.model.frame.RenderedFrame) {
// Cannot use 2nd level cache with rendered frames // Cannot use 2nd level cache with rendered frames
var callbackFirstLvlCacheOnly = this.onProcessorComplete_.bind(this, deferred, cache, key1, key1); var callbackFirstLvlCacheOnly = this.onProcessorComplete_.bind(this, deferred, cache, key1/*, key1*/);
this.frameProcessor(frame, callbackFirstLvlCacheOnly); this.frameProcessor(frame, callbackFirstLvlCacheOnly);
} else { } else {
var framePixels = JSON.stringify(frame.getPixels()); // TODO: Remove?
/*var framePixels = new Float64Array(frame.pixels.buffer).toString();
var key2 = pskl.utils.hashCode(framePixels); var key2 = pskl.utils.hashCode(framePixels);
if (cache[key2]) { if (cache[key2]) {
processedFrame = this.outputCloner(cache[key2], frame); processedFrame = this.outputCloner(cache[key2], frame);
cache[key1] = processedFrame; cache[key1] = processedFrame;
} else { } else {*/
var callback = this.onProcessorComplete_.bind(this, deferred, cache, key1, key2); var callback = this.onProcessorComplete_.bind(this, deferred, cache, key1/*, key1*/);
this.frameProcessor(frame, callback); this.frameProcessor(frame, callback);/*
} }*/
} }
if (processedFrame) { if (processedFrame) {
@ -53,9 +54,9 @@
return deferred.promise; return deferred.promise;
}; };
ns.AsyncCachedFrameProcessor.prototype.onProcessorComplete_ = function (deferred, cache, key1, key2, result) { ns.AsyncCachedFrameProcessor.prototype.onProcessorComplete_ = function (deferred, cache, key1/*, key2*/, result) {
cache[key1] = result; cache[key1] = result;
cache[key2] = result; //cache[key2] = result;
deferred.resolve(result); deferred.resolve(result);
}; };
})(); })();

View File

@ -71,16 +71,21 @@
processedFrame = this.frameProcessor(frame); processedFrame = this.frameProcessor(frame);
cache[cacheKey] = processedFrame; cache[cacheKey] = processedFrame;
} else { } else {
var framePixels = JSON.stringify(frame.getPixels()); // TODO: Remove?
/*
// Float64Array.toString() is about 2.4x times faster compared to Uint32Array.toString()
var framePixels = new Float64Array(frame.pixels.buffer).toString();
var frameAsString = pskl.utils.hashCode(framePixels); var frameAsString = pskl.utils.hashCode(framePixels);
if (cache[frameAsString]) { if (cache[frameAsString]) {
this.cacheHitLvl2_++;
processedFrame = this.outputCloner(cache[frameAsString], frame); processedFrame = this.outputCloner(cache[frameAsString], frame);
} else { } else {
processedFrame = this.frameProcessor(frame); */processedFrame = this.frameProcessor(frame);/*
cache[frameAsString] = processedFrame; cache[frameAsString] = processedFrame;
} }
cache[cacheKey] = processedFrame; cache[cacheKey] = processedFrame;*/
} }
return processedFrame; return processedFrame;
}; };
})(); })();