Skip to content

net: Store memory cache to disk on shutdown - #47244

Closed
Narfinger wants to merge 2 commits into
servo:mainfrom
Narfinger:memory-to-disk
Closed

Narfinger wants to merge 2 commits into
servo:mainfrom
Narfinger:memory-to-disk

Conversation

@Narfinger

@Narfinger Narfinger commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Need to do performance measurements.

This stores the memory cache to disk on shutdown if the disk cache is enabled.

On start of the browser the entries will be automatically promoted to the memory cache if used.

We also remove the second type parameter from async_runtime::spawn_blocking as it is not needed.

Testing: No automated test exist but this was manually verified.

@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Aug 14, 2026
Comment thread components/net/http_cache.rs Resolved
Signed-off-by: Narfinger <[email protected]>
@webbeef

webbeef commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Saving on shutdown won't help much on mobile where the app can be killed willy-nilly, and also in other situations like Beaver in "session" mode which is never shutdown.

@Narfinger

Copy link
Copy Markdown
Contributor Author

What would be a better way to do this?

@webbeef

webbeef commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

What would be a better way to do this?

I thought the general setup would be something along these lines:

  • when sending a fetch request, check if the resource is available from the memory cache. If not, check if it's available from the disk cache. If so, promote to memory cache, and return the response. If not, fetch from network.
  • when receiving the response, if we should cache it based on the various cache control values: store in memory cache, and also in the disk cache. Manage eviction in both caches based on size / other policy.

@Narfinger

Copy link
Copy Markdown
Contributor Author

There was discussion in #43819 about the design. I am not sure how to change it now, as it took quite a bit of time to get it reviewed and merged.

@Narfinger
Narfinger marked this pull request as draft August 14, 2026 15:12
@mrobinson

Copy link
Copy Markdown
Member

I agree that saving disk cache on shutdown is not a valid long term solution. If this lands as-is, it will need to be rewritten. Crashes, the OOM killer, and mobile operating systems should not interfere with disk cache. cc @janvarga who has a lot of storage experience.

@Narfinger

Copy link
Copy Markdown
Contributor Author

I opened a zulip discussion #general > DiskCache design and saving. because I am kind of at a loss what to do now.

@janvarga

Copy link
Copy Markdown
Member

I agree that saving disk cache on shutdown is not a valid long term solution. If this lands as-is, it will need to be rewritten. Crashes, the OOM killer, and mobile operating systems should not interfere with disk cache. cc @janvarga who has a lot of storage experience.

Sorry for the late reply, I somehow missed this discussion.

I agree with the concerns here. From our experience with Firefox, doing too much I/O during shutdown is something we should try to avoid. We had quite a few issues with shutdown taking too long, sometimes leading to hangs or crashes.

There is also the mobile aspect. On Android especially, we learned the hard way that shutdown cannot be relied on, since the application can be terminated without having a chance to shut down properly.

I think it would be better if Servo had a memory/disk cache design that doesn't depend on shutdown for saving data, ideally doing very little I/O during shutdown, or none at all.

@Narfinger

Copy link
Copy Markdown
Contributor Author

Closing because a functionality in NetworkManager exists to store the cache to disk.

@Narfinger Narfinger closed this Nov 17, 2026
@Narfinger
Narfinger deleted the memory-to-disk branch November 17, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants