Skip to main content

Module AssetMemoryMap

Module AssetMemoryMap 

Source
Expand description

Memory-mapped asset cache for the bundled workbench (and any other static-disk asset served via vscode-file://, tauri://, or land:// scheme handlers).

§Why mmap and not Vec<u8>

The bundled workbench under Element/Sky/Target/Static/Application/ ships ~80 MB of .js, .css, .svg, and font assets. Per-request fs::read pays a read(2) + alloc + memcpy of the full file; a LRU<String, Vec<u8>> cache duplicates the kernel page cache (memory held twice). memmap2::Mmap hands the webview a borrowed slice of file-backed pages that the OS evicts under pressure.

§Brotli sibling

Each entry transparently picks up an optional <file>.br produced by Maintain/Build/Brotli/Pre-Bake.ts. Scheme handlers can serve the pre-compressed bytes with Content-Encoding: br when the client offers it.

§Concurrency / eviction

DashMap shards are wait-free for read; first-load races on one shard lock. No eviction today - bundle is bounded by ~80 MB.

Modules§

CacheStats
Snapshot of asset-cache occupancy. Returned by Cache::AssetMemoryMap::Stats::Fn.
Clear
Clear the entire asset cache. Called on shutdown or on an explicit flush signal.
Entry
Single mmap-backed asset cache entry. Holds the file-backed mapping plus metadata computed once at load time.
Invalidate
Drop a single cached entry. Useful for hot-reload during dev when the bundler rewrites a chunk.
LoadOrInsert
Load Path into the cache (or return the existing entry).
Map 🔒
Process-global asset cache backing store. Lazily initialised on first request.
MimeFromExtension 🔒
Map a file extension to its IANA media type. Mirrors the inline helper in Binary/Build/Scheme.rs so the cache layer is self-contained.
Stats
Snapshot of asset-cache stats for diagnostics.