| Benchmark | Before | After | Δ |
|---|---|---|---|
| cache hit (disk, cached page) | 2.43 ms | 0.12 ms | ~20x |
| cache put+get | 170 µs | 98 µs | -42% |
| extraction, medium article | 13.9 ms | 8.2 ms | -41% |
| re-render of a large document | 12.5 ms | 4–8 µs | ~2000x |
| menu redraw (cache stats) | one directory scan per frame | memoized | no disk I/O per key |
What changed:
- The session page cache (
page_memory.go). The disk cache already made a page you read open in ~2 ms; the new in-memory layer removes the read too, so back and forward do no filesystem work. It is bounded to 24 pages / 24 MB and respects thecachesetting. - The rendered-document cache (
render_cache.go).renderDocis the most expensive stage after extraction, and it was repeated for every resize and every return to a page. Rendered documents are now kept in a 12-entry / 48 MB LRU keyed by the Markdown, the width, the layout options and the palette generation; a hit is a map lookup (BenchmarkRenderCached). - A one-pass
sanitize. The control-character regexp ran over every page, including every cache hit. It now takes a byte fast path and only rebuilds the string rune by rune when it must. - Memoized cache stats. The menu asked the cache directory for its page and byte counts on every redraw and once per filter entry. The numbers are now refreshed at most every two seconds and invalidated when the cache changes.
- Pruning once an hour.
cachePutwalked the whole cache directory after every saved page; with thousands of pages that is a visible delay on the fetch path. The age-based prune is now throttled to one walk per hour (and reset when the cache is cleared), which keeps the disk bounded without taxing every page load.