Skip to main content

Mountain/Cache/
AssetMemoryMap.rs

1#![allow(non_snake_case)]
2
3//! Memory-mapped asset cache for the bundled workbench (and any other
4//! static-disk asset served via `vscode-file://`, `tauri://`, or `land://`
5//! scheme handlers).
6//!
7//! ## Why mmap and not `Vec<u8>`
8//!
9//! The bundled workbench under `Element/Sky/Target/Static/Application/` ships
10//! ~80 MB of `.js`, `.css`, `.svg`, and font assets. Per-request `fs::read`
11//! pays a `read(2)` + alloc + memcpy of the full file; a `LRU<String,
12//! Vec<u8>>` cache duplicates the kernel page cache (memory held twice).
13//! `memmap2::Mmap` hands the webview a borrowed slice of file-backed pages
14//! that the OS evicts under pressure.
15//!
16//! ## Brotli sibling
17//!
18//! Each entry transparently picks up an optional `<file>.br` produced by
19//! `Maintain/Build/Brotli/Pre-Bake.ts`. Scheme handlers can serve the
20//! pre-compressed bytes with `Content-Encoding: br` when the client offers it.
21//!
22//! ## Concurrency / eviction
23//!
24//! `DashMap` shards are wait-free for read; first-load races on one shard
25//! lock. No eviction today - bundle is bounded by ~80 MB.
26
27pub mod CacheStats;
28pub mod Clear;
29pub mod Entry;
30pub mod Invalidate;
31pub mod LoadOrInsert;
32pub mod Stats;
33
34pub(crate) mod Map;
35pub(crate) mod MimeFromExtension;