On the back-end, I believe that Session Restore should be backed by a database, with each tab updated independently, rather than a big bunch of JSON data. The rationale being that:
- it's performance-critical;
- it's safety-critical;
- we have users with 300+ Mb of data in their Session Restore and JSON isn't meant for this scale of data;
- we wouldn't need to rewrite x Mb of data every 15 seconds, just a per-tab update;
- if we're using a relational database, it would be easier to trust the code to not screw up with the data;
- we wouldn't need to load the entire Session Restore upon startup.
(On the minus side, this might make backups a bit more complicated.)
On the front-end, we would need a high-level API for Session Restore, which would let us do things such as accessing per-tab data, (de)hibernating tabs, etc. Oh, and it would need to be accessible by WebExtensions.
In the middle, we would need to re-engineer Session Restore to make sure that we don't need to maintain this huge object representing the entire state of the session. We would also need improvements e.g. to cookie management, to avoid having to re-collect cookies so often.
Why not just use the filesystem? Imagine a layout like this:
+ profilename.default
|--+ sessionrestore
|--+ <timestamp>
|--+ window1
| |--+ tab1
| | |--- cookies
| | |--- formdata
| | |--- title
| | |--- url
| ---+ tab2
| |--- cookies
| |--- formdata
| |--- title
| |--- url
---+ window2
|--+ tab1
| |--- cookies
| |--- formdata
| |--- title
| |--- url
---+ tab2
|--- cookies
|--- formdata
|--- title
|--- url
One directory per timestamp, containing one directory per window, containing one directory per tab, containing one file per data type. All plain-text. Change a tab, just write to that tab's files, and update the timestamp directory name. Every x minutes, make a new timestamp tree, keeping y old ones as backups.No serializing and writing entire sessions to disk at once. Only small writes to small files. All plain-text, easy to read outside of the browser. Easy to copy, backup, modify, troubleshoot. No complex JSON, serializing, or database code. Use the write-to-temp-file-then-rename-over-existing-files paradigm to get atomic updates.
Need to know if part of a session on disk is stale? Check the mtime for that file, see if it's older than the last time that data was changed in memory.
Simple stuff. Straightforward. No overengineering. No bloat.
Why not do this?
It's a non-issue anyways, I have yet to see anyone show any actual evidence of an ssd dying prematurely or suffering degraded performance from this behaviour.
Also, people who keep Session Restore tabs open (you know, the tab that lets you restore your session, when you have crashed) and continue browsing – Firefox needs to store several nested Session Restore JSON files.