Firefox/session restore: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
m (→‎Sqlite: Style)
m (→‎Forgetting closed tabs/windows after a time: Fixed URL + reformulated text.)
Line 330: Line 330:


== Forgetting closed tabs/windows after a time ==
== Forgetting closed tabs/windows after a time ==
Done as part of [https://bugzilla.mozilla.org/show_bug.cgi?id=989393| bug 989393]. Statistics shows that this had no effect on the size of sessionstore.js.
Done as part of [https://bugzilla.mozilla.org/show_bug.cgi?id=989393 bug 989393]. Statistics shows that this had no big effect on the size of sessionstore.js at the moment.


== Forgetting closed tabs/windows when Firefox closes normal ==
== Forgetting closed tabs/windows when Firefox closes normal ==
TBD
TBD

Revision as of 07:33, 24 June 2014

What is Session Restore, why this page?

Session Restore is the service that saves the state of Firefox while the user is browsing so as to be able to restore it after a shutdown or a crash.

This service is extremely useful but is also quite expensive. It was designed a long time ago, when users only had a few tabs, when DOM Storage didn't exist and before people started uploading Gigabytes of data. For this reason, it is undergoing major refactorings and redesigns.

This page is about documenting things progressively.

Collecting and saving data

TBD

Data we collect

  • Open windows and tabs
  • Closed windows and tabs (closed tabs, tabs in closed windows, closed tabs in closed windows)
  • Loaded pages before and after (back and forward buttons)
  • Form data (for the case of a browser or system crash)
  • ... (TBD)

Data we do *not* collect

  • ... (TBD)

Privacy

TBD

Technicality informations

Paths and file

Windows XP: TBD
Windows 7: [system-drive]:\Users\[user-name]\AppData\Roaming\Mozilla\Firefox\Profiles\[profile-name[.default]]\
Linux: TBD
Mac OS X: TBD
... (TBP)

File: sessionstore.js

Backups interval: The file is saved whenever a change that needs to be saved is detected, with a cap that forces at least 15 seconds (by default) between two successive changes.

Backups files:
- sessionstore.bak
- sessionstore.bak-[yyyymmddtttttt]

Browser settings

browser.sessionhistory.max_entries:
The maximum number of session history entries to keep in working memory (which includes the 'current' page).
Default: 50

browser.sessionhistory.max_total_viewers:
TBP
Default: -1

browser.sessionstore.debug:
TBP
Default: false

browser.sessionstore.interval:
TBP
Default: 15000ms

browser.sessionstore.max_resumed_crashes:
TBP
Default: 1

browser.sessionstore.max_serialize_back:
The maximum number of 'back button' session history entries to store in sessionstore.js.
Default: 10 (-1 = no limit)

browser.sessionstore.max_serialize_forward:
The maximum number of 'forward button' session history entries to store in sessionstore.js.
Default: -1 (-1 = no limit)

browser.sessionstore.max_tabs_undo:
TBP
Default: 10

browser.sessionstore.max_windows_undo:
TBP
Default: 3

browser.sessionstore.privacy_level:
TBP
Default: 0

browser.sessionstore.privacy_level_deferred:
TBP
Default: 1

browser.sessionstore.restore_hidden_tabs:
TBP
Default: false

browser.sessionstore.restore_on_demand:
TBP
Default: true

browser.sessionstore.restore_pinned_tabs_on_demand:
TBP
Default: false

browser.sessionstore.resume_from_crash:
TBP
Default: true

browser.sessionstore.resume_session_once:
TBP
Default: false

browser.sessionstore.upgradeBackup.latestBuildID:
TBP
Value: yyyymmddtttttt

services.sync.prefs.sync.browser.sessionstore.restore_on_demand:
TBP
Default: true

View content

With extension:
Add-on: https://addons.mozilla.org/en-US/firefox/addon/about-sessionstore/
Author: https://addons.mozilla.org/en-US/firefox/user/dtryse/
(This extension is also be able to "Forget closed tabs" and "Forget closed windows". Also shows settings, timings and size.)

Restoring sessions

TBD

Telemetry

Early Telemetry indicates that 75% percent of Nightly users have a sessionstore.js weighing 194kb or less and 95% of users have 1.2Mb or less:
http://telemetry.mozilla.org/#nightly/29/FX_SESSION_RESTORE_FILE_SIZE_BYTES

And 100k+ users have a sessionstore.js >10MB.

The disk writes to sessionstore.js over an 8 hour day can be big:
https://bugzilla.mozilla.org/attachment.cgi?id=8443670

The structure of sessionstore.js

  • windows the currently opened windows (array)
    • tabs the currently opened tabs (array)
      • attributes a set of attributes persisted for the tab (object)
        • TBD (unused?)
      • entries the history of the tab (array)
        • TBD
      • extData a key/value store used by clients of Session Restore to store permanent information (object, optional)
      • hidden
      • image URL of the favicon used for this tab (string)
      • index
        • TBD
      • lastAccessed (ms since epoch)
        • TBD
      • pinned is the tab pinned? (boolean)
      • closedAt if the tab is closed, the date at which it was closed (optional, ms since epoch)
    • selected the index of the currently selected tab in tabs(number)
    • _closedTabs the currently closed tabs (array)
      • (structure is the same as tabs)
    • busy is the window currently busy restoring/duplicating a tab? (boolean)
    • cookies the Session Cookies set for this window (array)
      • expiry (number)
      • host (string)
      • name (string)
      • path (string)
      • value (string)
    • extData a key/value store used by clients of Session Restore to store permanent information (object, optional)
    • height height of the window in pixels (number)
    • width width of the window in pixels (number)
    • screenX horizontal position of the window in pixels (number)
    • screenY vertical position of the window in pixels(number)
    • sizemode (one of "minimized", "maximized", "normal")
  • selectedWindow the index of the currently selected window in windows
  • _closedWindows the currently closed windows (array)
    • (structure is the same as windows)
  • session metadata on the session itself
    • lastUpdate date of the last update (milliseconds since epoch)
    • startTime date of the session start (ms since epoch)
    • recentCrashes number of crashes since the latest good start
  • global
    • TBD
  • scratchpads (optional)
    • TBD
  • lastSessionState if we deferred referring a session, a representation of this session (optional)
    • (same structure as sessionstore.js)
  • deferredInitialState (optional)
    • TBD

Redesigning sessionstore.js

Bug 669034 - (sessionRestoreJank) [meta] Re-architect session restore to avoid periodic freezes
Bug 810932 - Investigate how to redesign sessionstore.js for improved performance
Bug 934934 - [meta][Session Restore] Track sites that spam sessionstore.js, find defensive strategies

Our problems

During startup

We need to read + parse everything, even when we restore-on-demand or do not restore at all:

  • Slower startup
  • Much I/O
  • CPU-hungry
  • Memory-hungry

During runtime

We need to serialize + write everything, even when only a single tab has changed.

  • Slower runtime
  • Much I/O
  • CPU-hungry
  • Memory-hungry

During shutdown

  • During shutdown, final serialize + write everything
  • Much I/O (annoying)
  • Slower shutdown (less annoying)
  • CPU-hungry (less annoying)
  • Memory-hungry (less annoying)


Improvements

Reduce amount of data stored

Good for: everything.

Limitations: there is only so much data we can cull away.

Difficulty: 2/5.

Compress data

Good for:

  • startup I/O;
  • runtime I/O;
  • shutdown I/O.

Bad for:

  • CPU (not much);
  • Memory (not much);
  • Human readability (a lot).

Difficulty: 1/5.

Journalize files, consolidate them on idle-daily and shutdown

Good for reducing serialize + write:

  • runtime I/O;
  • runtime CPU use;
  • runtime memory use.

Bad for:

  • shutdown CPU use (probably not a big deal);
  • shutdown memory use;
  • runtime I/O, CPU, memory in case of crash;
  • addon-compat;
  • getBrowserState() & co. use a different path from SessionSaver.run.

The consolidated version would not hurt readability.

Difficulty: 3/5.

(Most likely.)

Save separately index (one file), tabs (one file per tab)

Good for:

  • startup I/O (unless the user);
  • startup CPU;
  • startup memory;
  • startup duration;
  • runtime I/O;
  • runtime CPU;
  • runtime memory;
  • runtime duration.

Bad for:

  • garbage-collecting files may be difficult;
  • addon-compat;
  • getBrowserState() & co. use a different path from SessionSaver.run.

Readability would be ok.

Difficulty: 4/5.

Binary format that can be loaded/modified piecewise

Good for:

  • startup I/O;
  • startup CPU;
  • startup memory;
  • startup duration;
  • runtime I/O;
  • runtime CPU;
  • runtime memory;
  • runtime duration;

Bad for:

  • debugging;
  • extensibility;
  • garbage-collecting will be difficult;
  • getBrowserState() & co. use a different path from SessionSaver.run();
  • readability.

Difficulty: 5/5.

SQLite

Good for:

  • startup I/O;
  • startup CPU;
  • startup memory;
  • startup duration;
  • runtime I/O;
  • runtime CPU;
  • runtime memory;
  • runtime duration.

Bad for:

  • backups;
  • use of flush() is bad for battery & rest of the system;
  • garbage-collection will be moderately difficult;
  • getBrowserState() & co. use a different path from SessionSaver.run.

Difficulty: 3/5.

Bug 937651 - Replace the sessionstore.js with an sessionstore.sqlite

https://en.wikipedia.org/wiki/SQLite

Other DBMS

?

Reducing the amount of data we store

History entries

TBD

DOM Session Storage

TBD

POST data

TBD

Forgetting closed tabs/windows after a time

Done as part of bug 989393. Statistics shows that this had no big effect on the size of sessionstore.js at the moment.

Forgetting closed tabs/windows when Firefox closes normal

TBD