Problem/Motivation
Once we can generate SVGs from D2 input (see: #3565334: Generate SVG from D2 input), we should cache these generated SVGs, since they should only change when the source D2 is updated.
Proposed resolution
We should be able to use a hash of the D2 input as a key to avoid re-generating SVGs continuously. It should also be safe to leave older SVGs in-place, and just let them be garbage-collected on cache rebuilds.
Remaining tasks
TBD
Comments
Comment #2
ergonlogicComment #3
ergonlogicWe need #3565334: Generate SVG from D2 input before we can cache the results.
Comment #4
ergonlogicComment #7
ergonlogicI added some basic caching. Initially I wasn't seeing any change in performance, but then realized internal render and page caching was probably nullifying my attempts to observe an improvement. So I disabled caching in our local dev environment, and saw a significant improvement with Apache Bench:
Note that this almost 3x improvement is mostly just process overhead, since the D2 diagram itself is trivial. The difference becomes significantly larger (>10x) with even a moderate D2 diagram (such as the one from the front page of https://d2lang.com).
We can explore more caching options (bins, tags, etc.) later. But this is definitely good enough for now.