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

ergonlogic created an issue. See original summary.

ergonlogic’s picture

ergonlogic’s picture

Status: Active » Postponed

We need #3565334: Generate SVG from D2 input before we can cache the results.

ergonlogic’s picture

Version: » 1.0.x-dev
Status: Postponed » Active

  • ergonlogic committed b253b45e on 1.0.x
    feat: #3565335 Disable caching in local dev environment
    

ergonlogic’s picture

Status: Active » Fixed

I 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:

# before caching
$ ab -n 100 -c 10 https://d2.ddev.site/node/1
[...]
Requests per second:    28.42 [#/sec] (mean)                                                                                                       
Time per request:       351.835 [ms] (mean)
[...]
# after caching
$ ab -n 100 -c 10 https://d2.ddev.site/node/1
[...]
Requests per second:    80.49 [#/sec] (mean)
Time per request:       124.236 [ms] (mean)
[...]

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.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.