Closed Bug 661866 Opened 13 years ago Closed 13 years ago

Save sessionstore thumbnails in a separate file-based cache

Categories

(Firefox for Android Graveyard :: General, defect)

x86
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: mfinkle, Assigned: mfinkle)

Details

Attachments

(1 file)

Attached patch patchSplinter Review
The SessionStore JSON file holds the dataURL (base64) of the thumbnail for each open tab. The thumbnail data is usually between 2KB and 7KB, depending on the tab. The JSON file can easily grow to over 30KB - usually bigger.

This has a performance impact when reading and writing the session state, which can happen a lot while the application is running. It also affects the startup time when loading the previous session.

Since the data is attached to each tab JS object, we also incur a runtime memory increase.

The data is only every used to show the tab thumbnail in cases of a startup-from-crash or runtime content-crash. It's not needed very often.

This patch moves the actual image data to a sessionstoreCache folder in the profile, saved as PNG files. The sessionstore.js file still has a URI to the thumbnail, it's now a file URI and not a data URI.

The patch also clears unused image data from the cache during startup and when private data is cleared. We could add more "eviction" triggers, but this seems fine for now.

The sessionstore.js file now hovers around 1KB - 3KB.
Attachment #537168 - Flags: review?(21)
Comment on attachment 537168 [details] [diff] [review]
patch


>diff --git a/mobile/components/SessionStore.js b/mobile/components/SessionStore.js
>+
>+  _clearCache: function ss_clearCache() {
>+    // First, let's get a list of files we think should be active
>+    let activeFiles = [];
>+    this._forEachBrowserWindow(function(aWindow) {
>+      let tabs = aWindow.Browser.tabs;
>+      for (let i = 0; i < tabs.length; i++) {
>+        let browser = tabs[i].browser;
>+        if (browser.__SS_extdata && "thumbnail" in browser.__SS_extdata)
>+          activeFiles.push(browser.__SS_extdata.thumbnail);
>+      }
>+    });
>+
>+    // Now, let's find the stale files in the cache folder
>+    let staleFiles = [];
>+    let cacheFiles = this._sessionCache.directoryEntries;
>+    while (cacheFiles.hasMoreElements()) {
>+      let file = cacheFiles.getNext().QueryInterface(Ci.nsILocalFile);
>+      let fileURI = Services.io.newFileURI(file);
>+      if (activeFiles.indexOf(fileURI) == -1)
>+        staleFiles.push(file);
>+    }

Is _clearCache  called even during a normal session?
If yes I wonder if reading from the hard-drive can slow down startup?
Comment on attachment 537168 [details] [diff] [review]
patch

My question has been answered on IRC and the normal startup time won't be affected since the clearCache call is done only once the first browser window is loaded.
Attachment #537168 - Flags: review?(21) → review+
pushed
http://hg.mozilla.org/mozilla-central/rev/c445c7ba9a4e
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
bugspam
Assignee: nobody → mark.finkle
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: