Skip to main content

Module per_buffer_cache

Module per_buffer_cache 

Source
Expand description

PerBufferCache<T> — per-buffer cache primitive for the 5.8.AF.5 Slice 3b migration.

Every LSP feature that produces a per-buffer cache (inlay hints, folding ranges, semantic tokens, code lenses, document links, document colors, pull diagnostics, …) needs:

  • Wait-free reads at render time (renderer paints every frame; can’t take a lock).
  • Concurrent writes from background tasks on the LSP runtime (the spawned request task .store()s the result when the response arrives — paramount goal #4).
  • Per-buffer keying so closing buffer A doesn’t affect buffer B’s cache.
  • Shareability so the renderer’s RenderState snapshot can hold a clone that observes writes by the task.

Arc<ArcSwap<HashMap<BufferId, Arc<T>>>> satisfies all four:

  • The outer Arc lets the spawned task clone the slot into itself.
  • The ArcSwap makes the inner HashMap swappable atomically.
  • The inner Arc<T> per entry lets readers detach a value cheaply (one Arc bump) without holding a lock.
  • The ArcSwap snapshot is wait-free for readers.

Writes are copy-on-write: a writer loads the current Arc<HashMap>, clones the underlying HashMap, mutates the clone, and stores. For typical sessions (~5–50 open buffers) the clone cost is microseconds and writes are rare (~1 per LSP response per cache type), so the cost stays well below the 100µs publication budget.

Traits§

PerBufferCacheExt
Convenience trait carrying the standard read / insert / remove operations for a PerBufferCache.

Functions§

empty
Construct an empty PerBufferCache<T>. The Slice 3b boot path uses this; downstream code clones the resulting Arc.

Type Aliases§

PerBufferCache
Per-buffer cache slot — the canonical Slice 3b shape for per-buffer LSP feature data.