Open Bug 2096757 Opened 6 days ago Updated 1 day ago

Session restore may be writing session files despite no data changes

Categories

(Firefox :: Session Restore, defect)

defect

Tracking

()

People

(Reporter: sthompson, Unassigned)

References

(Blocks 1 open bug)

Details

I did some quick investigation based on a report on bug 1849393 comment 91 by Dino.

I don't have that much tab open right now in Firefox and if I leave it completely idle/sleeping, it fully overwrites the recovery.jsonlz4 file every 15 seconds and rewrite the exact same content (maybe except the timestamp?), which is pretty pointless... but that's 5MB written to the disk every 15 seconds, which is over 10 TERABYTES a year !

That certainly seemed pointless, so I poked around a bit and tried some diagnostics. Findings:

  1. The interval between writes is supposed to be capped (by default) to 15 seconds for an active user and 1 hour for an idle user. By default, the browser should be considered idle after 3 minutes of computer inactivity.
  2. There are a lot of invocations for SessionStore#saveStateDelayed and they generally have no guards against data values staying intact. Many of these saves occur when there is definitely going to be data to save (adding a tab, opening a tab, removing a tab, etc.) but there are some avenues for triggering a save despite no data changes.
  3. Add-ons that set custom data will trigger a save. In theory, an over-eager add-on could frequently set the same value(s) and cause us to write a session file even though nothing changed. I didn't test this empirically.
  4. #onTabStateUpdate governs a lot of the tab data. I opened a few tabs, including a news web site. The news web site's tab raised a tab state update every 60 seconds. The data included all of formdata, scroll, historychange every 60 seconds, but after leaving the web page untouched for a while, every update did not actually change the values for formdata, scroll, or history. I confirmed that the session file was re-written every 60 seconds despite no changes to that tab. I confirmed that the tab state update was the only thing that caused the session write to occur.

So I think there could be room to suppress session file writes even without a rearchitecture. Comparisons between existing tab state and proposed tab state updates would take extra CPU and memory at runtime, but for some combinations of web sites and user behavior, it could avoid the overhead of serializing session state and writing it to disk.

If a web site is constantly making real changes to formdata, storage, history, etc. then this optimization wouldn't end up preventing any session file writes. I don't know how common such web sites might be.

I did investigate today too with SWE-2.1 in Devin (I'm surprised this bug is reported in few days ago)
and a small patch is made
https://gist.github.com/nyanrus/56e119e5b5760523230d73d4efff4c22
Would this be good to submitted here to be reviewed?

You need to log in before you can comment on or make changes to this bug.