Firefox/session restore: Difference between revisions
m (→The structure of sessionstore.js: Added "userTypedValue".) |
|||
| Line 143: | Line 143: | ||
** <code>tabs</code> the currently opened tabs (array) | ** <code>tabs</code> the currently opened tabs (array) | ||
*** <code>attributes</code> a set of attributes persisted for the tab (object) | *** <code>attributes</code> a set of attributes persisted for the tab (object) | ||
**** TBD (unused?) | **** <code>userTypedValue</code> is an optional attribute. When it is present, it stores the text entered by the user in the address bar. | ||
**** ... (TBD) (unused?) | |||
*** <code>entries</code> the history of the tab (array) | *** <code>entries</code> the history of the tab (array) | ||
**** <code>url</code> (string) | **** <code>url</code> (string) | ||
Revision as of 13:51, 25 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.sessionstore.cleanup.forget_closed_after:
TBP
Default: ??? (TBP)
Since: Target for Firefox 32
browser.sessionhistory.max_entries:
The maximum number of session history entries to keep in working memory (which includes the 'current' page).
Default: 50
Since: Firefox 30
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)
Since: Firefox 30
browser.sessionstore.max_serialize_forward:
The maximum number of 'forward button' session history entries to store in sessionstore.js.
Default: -1 (-1 = no limit)
Since: Firefox 30
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
windowsthe currently opened windows (array)tabsthe currently opened tabs (array)attributesa set of attributes persisted for the tab (object)userTypedValueis an optional attribute. When it is present, it stores the text entered by the user in the address bar.- ... (TBD) (unused?)
entriesthe history of the tab (array)url(string)title(string, optional)subframeis this an entry in a subframe? (boolean, optional)cacheKeyTBD (string, optional, need to check whether this is still good/useful with cache v2)IDTBD (string, optional, unused?)docshellIDID of the document owning this entry (string, buggy and possibly useless)refererrURIURI of the referrer (string, optional)srcdocdataif the document was loaded from an inline srcdoc, the data that was loaded instead of the URI (string, optional)isSrcdocEntrywas the document loaded from an inline srcdoc? (boolean, optional, could apparently be removed)baseURIused for srcdoc loads to give view-source knowledge of the load's base URI as this information isn't embedded in the load's URI.(string, optional)scrollx, y coordinates (string, optional)owner_b64serialized owner (string, optional, no clue what it's for)docIdentifierTBD, cache related (string, optional, need to check whether this is still good/useful with cache v2)structuredCloneStatepushState state (string, optional)structuredCloneVersionversion of the algorithm required to restorestructuredCloneState(number, optional)childrenif this document has frames, entries for each frame(array, optional)- structure is the same as
entries
- structure is the same as
extDataa key/value store used by clients of Session Restore to store permanent information (object, optional)hiddenimageURL of the favicon used for this tab (string)indexindex of the currently active entry inentries(number)lastAccesseddate of the last interaction with this tab (number of ms since epoch)pinnedis the tab pinned? (boolean)userTypedValuetest entered by the user on the address bar (string, optional)closedAtif the tab is closed, the date at which it was closed (optional, ms since epoch)
selectedthe index of the currently selected tab intabs(number)_closedTabsthe currently closed tabs (array)- (structure is the same as
tabs)
- (structure is the same as
busyis the window currently busy restoring/duplicating a tab? (boolean)cookiesthe Session Cookies set for this window (array)expiry(number)host(string)name(string)path(string)value(string)
extDataa key/value store used by clients of Session Restore to store permanent information (object, optional)heightheight of the window in pixels (number)widthwidth of the window in pixels (number)screenXhorizontal position of the window in pixels (number)screenYvertical position of the window in pixels(number)sizemode(one of "minimized", "maximized", "normal")
selectedWindowthe index of the currently selected window inwindows_closedWindowsthe currently closed windows (array)- (structure is the same as
windows)
- (structure is the same as
sessionmetadata on the session itselflastUpdatedate of the last update (milliseconds since epoch)startTimedate of the session start (ms since epoch)recentCrashesnumber of crashes since the latest good start
globala key/value store used by clients of Session Restore to store permanent information (object, optional)scratchpadsstate of the scratchpads (array, optional)- (out of the control of Session Restore)
lastSessionStateif we deferred restoring a session, a representation of this session (object, optional)- (same structure as sessionstore.js)
deferredInitialState(optional not sure I understand what it's for)- (same structure as sessionstore.js)
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);
- Backwards compatibility (a lot);
- Add-ons compatibility (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.
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
Via bug 989393 ???