anim-slides gallery

cache-compare

The same four reads raced on one clock without and with a cache; 180 ms database reads keep growing while 8 ms hits stop almost at once, and database load climbs to 96 % on one side but stays at 24 % on the other.

Without cache every read → database bars to scale read 1 180 ms read 2 180 ms read 3 180 ms read 4 180 ms load 0 % 24 % 48 % 72 % 96 % 0 reads 1 read 2 reads 3 reads 4 reads With cache miss → DB, fill, then cache hit read 1 185 ms read 2 8 ms read 3 8 ms read 4 8 ms load 0 % 24 % 0 reads 1 read 75 % fewer database reads First read misses and fills the cache Later reads hit the cache 22× faster on cache hits, 75 % fewer database reads illustrative

Swipe sideways to see the whole figure.

Download playable demo
Verb
race
Archetype
compare
Domain
software
viewBox
1680 × 600
Control
once: plays one pass, then rests on the finished state
Pass
10 s
Tags
caching, latency, database, before-after, performance
Files
cache-compare.html (fragment) · cache-compare-demo.html (playable page) · spec.yaml · thumb.png
Source
pool/cache-compare/

Paste the fragment into any HTML deck; it plays while an ancestor has the class visible (one pass for once, then it holds the finished state) and otherwise shows its resting frame. Rename the prefix (cache-compare) when you adapt it so it stays unique in your deck.

spec.yaml

# Same four reads with and without a read-through cache: the left side pays the database
# round trip every time and the database gets busy; on the right the first read misses and
# fills the cache, the rest hit it at about 8 ms. Scaffold with:
#   python3 scripts/scaffold_from_spec.py pool/cache-compare/spec.yaml -o pool/cache-compare/cache-compare.html
# The pool fragment is hand-built (verb race: per read, both latency bars start together and grow
# at the same rate on one scale; load meters step per database read; bracket on the load gap);
# re-scaffolding gives the row skeleton and timing only.
name: cache-compare
archetype: compare
verb: race
size: [1680, 600]
control: once
cycle: 10
nodes:
  - { id: l-r1, side: left,  group: nocache, label: "Read 1  → database", sub: "180 ms" }
  - { id: l-r2, side: left,  group: nocache, label: "Read 2  → database", sub: "180 ms" }
  - { id: l-r3, side: left,  group: nocache, label: "Read 3  → database", sub: "180 ms" }
  - { id: l-r4, side: left,  group: nocache, label: "Read 4  → database", sub: "180 ms, DB busy" }
  - { id: r-r1, side: right, group: cache,   label: "Read 1  miss, fill", sub: "185 ms" }
  - { id: r-r2, side: right, group: cache,   label: "Read 2  cache hit",  sub: "8 ms" }
  - { id: r-r3, side: right, group: cache,   label: "Read 3  cache hit",  sub: "8 ms" }
  - { id: r-r4, side: right, group: cache,   label: "Read 4  cache hit",  sub: "8 ms" }
groups:
  - { id: nocache, label: "Without cache" }
  - { id: cache,   label: "With cache" }
phases:
  - { t: 0,    label: setup,  show: [nocache, cache] }
  - { t: 0.5,  label: miss,   show: [l-r1, r-r1], active: [r-r1, l-r1], note: "First read misses and fills the cache" }
  - { t: 2.5,  label: hits,   show: [l-r2, l-r3, l-r4, r-r2, r-r3, r-r4], active: [r-r2, r-r3, r-r4], note: "Later reads hit the cache" }
  - { t: 7.4,  label: verdict, active: [cache], note: "22× faster on hits, 75 % fewer database reads" }
  - { t: 8.9,  label: hold }