Bug 834999 - WebappsApplication.prototype.manifest getter takes 25-30ms on critical startup path r=ferjm

This commit is contained in:
Fabrice Desré 2013-01-30 22:50:28 -08:00
parent 2d50ea3fac
commit bd1b69d976

View File

@ -333,6 +333,35 @@ DOMError.prototype = {
* mozIDOMApplication object
*/
// A simple cache for the wrapped manifests.
let manifestCache = {
_cache: { },
// Gets an entry from the cache, and populates the cache if needed.
get : function mcache_get(aManifestURL, aManifest, aWindow) {
dump("-- manifestCache::get() " + aManifestURL + "\n");
if (!(aManifestURL in this._cache)) {
dump("\twrapping\n");
this._cache[aManifestURL] = ObjectWrapper.wrap(aManifest, aWindow);
}
return this._cache[aManifestURL];
},
// Invalidates an entry in the cache.
evict: function mcache_evict(aManifestURL) {
dump("-- manifestCache::evict() " + aManifest + "\n");
if (aManifestURL in this._cache) {
dump("\tfound entry!\n");
delete this._cache[aManifestURL];
}
},
clear: function mcache_clear() {
dump("-- manifestCache::clear()\n");
this._cache = { };
}
}
function createApplicationObject(aWindow, aApp) {
let app = Cc["@mozilla.org/webapps/application;1"].createInstance(Ci.mozIDOMApplication);
app.wrappedJSObject.init(aWindow, aApp);
@ -387,7 +416,7 @@ WebappsApplication.prototype = {
},
get manifest() {
return this.manifest = ObjectWrapper.wrap(this._manifest, this._window);
return manifestCache.get(this.manifestURL, this._manifest, this._window);
},
get updateManifest() {
@ -483,6 +512,7 @@ WebappsApplication.prototype = {
["Webapps:OfflineCache",
"Webapps:PackageEvent",
"Webapps:CheckForUpdate:Return:OK"]);
manifestCache.clear();
},
_fireEvent: function(aName, aHandler) {
@ -572,6 +602,7 @@ WebappsApplication.prototype = {
this._fireEvent("downloadprogress", this._onprogress);
break;
case "installed":
manifestCache.evict(this.manifestURL);
this._manifest = msg.manifest;
this._fireEvent("downloadsuccess", this._ondownloadsuccess);
this._fireEvent("downloadapplied", this._ondownloadapplied);
@ -580,11 +611,13 @@ WebappsApplication.prototype = {
// We don't update the packaged apps manifests until they
// are installed or until the update is unstaged.
if (msg.manifest) {
manifestCache.evict(this.manifestURL);
this._manifest = msg.manifest;
}
this._fireEvent("downloadsuccess", this._ondownloadsuccess);
break;
case "applied":
manifestCache.evict(this.manifestURL);
this._manifest = msg.manifest;
this._fireEvent("downloadapplied", this._ondownloadapplied);
break;