Commit 1db0b467 authored by pfeldman@chromium.org's avatar pfeldman@chromium.org

2011-05-03 Pavel Feldman <pfeldman@chromium.org>

        Reviewed by Yury Semikhatsky.

        Web Inspector: revision history storage is too slow.
        https://bugs.webkit.org/show_bug.cgi?id=59939

        It turns out that iterating localStorage keys is very
        expensive (results in slow inspector start), refactor revision
        history in order not to rely upon that operation.

        * inspector/front-end/Resource.js:
        (WebInspector.Resource):
        (WebInspector.Resource._resourceRevisionRegistry):
        (WebInspector.Resource.restoreRevisions.persist):
        (WebInspector.Resource.restoreRevisions):
        (WebInspector.Resource.persistRevision):
        (WebInspector.Resource.prototype._persistRevision):
        * inspector/front-end/ResourceTreeModel.js:
        (WebInspector.ResourceTreeModel.prototype._processCachedResources):
        (WebInspector.ResourceTreeModel.prototype._frameNavigated):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@85591 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent fb1d4202
2011-05-03 Pavel Feldman <pfeldman@chromium.org>
Reviewed by Yury Semikhatsky.
Web Inspector: revision history storage is too slow.
https://bugs.webkit.org/show_bug.cgi?id=59939
It turns out that iterating localStorage keys is very
expensive (results in slow inspector start), refactor revision
history in order not to rely upon that operation.
* inspector/front-end/Resource.js:
(WebInspector.Resource):
(WebInspector.Resource._resourceRevisionRegistry):
(WebInspector.Resource.restoreRevisions.persist):
(WebInspector.Resource.restoreRevisions):
(WebInspector.Resource.persistRevision):
(WebInspector.Resource.prototype._persistRevision):
* inspector/front-end/ResourceTreeModel.js:
(WebInspector.ResourceTreeModel.prototype._processCachedResources):
(WebInspector.ResourceTreeModel.prototype._frameNavigated):
2011-05-03 Pavel Feldman <pfeldman@chromium.org>
Reviewed by Yury Semikhatsky.
......@@ -35,8 +35,6 @@ WebInspector.Resource = function(identifier, url, loaderId)
this._category = WebInspector.resourceCategories.other;
this._pendingContentCallbacks = [];
this.history = [];
this._restoreRevisions();
}
// Keep these in sync with WebCore::InspectorResource::Type
......@@ -111,15 +109,80 @@ WebInspector.Resource.registerDomainModelBinding = function(type, binding)
WebInspector.Resource._domainModelBindings[type] = binding;
}
WebInspector.Resource.clearRevisionHistory = function()
WebInspector.Resource._resourceRevisionRegistry = function()
{
if (!WebInspector.Resource._resourceRevisionRegistryObject) {
if (window.localStorage) {
var resourceHistory = window.localStorage["resource-history"];
try {
WebInspector.Resource._resourceRevisionRegistryObject = resourceHistory ? JSON.parse(resourceHistory) : {};
} catch (e) {
WebInspector.Resource._resourceRevisionRegistryObject = {};
}
} else
WebInspector.Resource._resourceRevisionRegistryObject = {};
}
return WebInspector.Resource._resourceRevisionRegistryObject;
}
WebInspector.Resource.restoreRevisions = function()
{
var registry = WebInspector.Resource._resourceRevisionRegistry();
var filteredRegistry = {};
for (var url in registry) {
var historyItems = registry[url];
var resource = WebInspector.resourceForURL(url);
var filteredHistoryItems = [];
for (var i = 0; historyItems && i < historyItems.length; ++i) {
var historyItem = historyItems[i];
if (resource && historyItem.loaderId === resource.loaderId) {
resource.addRevision(window.localStorage[historyItem.key], new Date(historyItem.timestamp), true);
filteredHistoryItems.push(historyItem);
filteredRegistry[url] = filteredHistoryItems;
} else
delete window.localStorage[historyItem.key];
}
}
WebInspector.Resource._resourceRevisionRegistryObject = filteredRegistry;
function persist()
{
window.localStorage["resource-history"] = JSON.stringify(filteredRegistry);
}
// Schedule async storage.
setTimeout(persist, 0);}
WebInspector.Resource.persistRevision = function(resource)
{
if (!window.localStorage)
return;
for (var key in window.localStorage) {
if (key.indexOf("resource-history|") === 0)
delete window.localStorage[key];
var url = resource.url;
var loaderId = resource.loaderId;
var timestamp = resource._contentTimestamp.getTime();
var key = "resource-history|" + url + "|" + loaderId + "|" + timestamp;
var content = resource._content;
var registry = WebInspector.Resource._resourceRevisionRegistry();
var historyItems = registry[resource.url];
if (!historyItems) {
historyItems = [];
registry[resource.url] = historyItems;
}
historyItems.push({url: url, loaderId: loaderId, timestamp: timestamp, key: key});
function persist()
{
window.localStorage[key] = content;
window.localStorage["resource-history"] = JSON.stringify(registry);
}
// Schedule async storage.
setTimeout(persist, 0);
}
WebInspector.Resource.Events = {
......@@ -763,52 +826,7 @@ WebInspector.Resource.prototype = {
_persistRevision: function()
{
if (!window.localStorage)
return;
var url = this.url;
var loaderId = this.loaderId;
var timestamp = this._contentTimestamp.getTime();
var content = this._content;
function persist()
{
var key = "resource-history|" + url + "|" + loaderId + "|" + timestamp;
window.localStorage[key] = content;
}
// Schedule async storage.
setTimeout(persist, 0);
},
_restoreRevisions: function()
{
if (!window.localStorage)
return;
try {
var urlKey = "resource-history|" + this.url + "|" + this.loaderId + "|";
var content = {};
var timestamps = [];
for (var key in window.localStorage) {
if (key.indexOf(urlKey) !== 0)
continue;
var timestamp = parseInt(key.substring(urlKey.length));
content[timestamp] = window.localStorage[key];
timestamps.push(timestamp);
}
if (!timestamps.length)
return;
timestamps.sort();
for (var i = 0; i < timestamps.length; ++i) {
var timestamp = timestamps[i];
this.addRevision(content[timestamp], new Date(timestamp), true);
}
} catch(e) {
console.error(e.toString());
}
WebInspector.Resource.persistRevision(this);
},
requestContent: function(callback)
......
......@@ -64,13 +64,16 @@ WebInspector.ResourceTreeModel.prototype = {
_processCachedResources: function(error, mainFramePayload)
{
if (error)
if (error) {
console.error(JSON.stringify(error));
return;
}
this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.WillLoadCachedResources);
WebInspector.mainResource = this._addFramesRecursively(mainFramePayload);
this._dispatchInspectedURLChanged(WebInspector.mainResource.url);
this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.CachedResourcesLoaded);
WebInspector.Resource.restoreRevisions();
this._cachedResourcesProcessed = true;
},
......@@ -142,7 +145,6 @@ WebInspector.ResourceTreeModel.prototype = {
if (isMainFrame && this.resourceForURL(frame.url)) {
WebInspector.mainResource = this.resourceForURL(frame.url);
this._dispatchInspectedURLChanged(frame.url);
WebInspector.Resource.clearRevisionHistory();
}
},
......
......@@ -178,8 +178,3 @@ WebInspector.setInspectedTabId = function(tabId)
{
WebInspector._inspectedTabId = tabId;
}
WebInspector.InspectorFrontendHostStub.prototype.inspectedURLChanged = function(url)
{
document.title = "Developer Tools - " + url;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment