Repository navigation
Commit 4d1c708
perf(site): compile the registry once per build, not twice (#139)
Astro loads `astro.config.mjs` in a module graph of its own, separate
from the one the pages render in. `src/lib/registry.ts` is therefore
instantiated twice in a single build, and the module-level memo is not
shared between the two copies. An instrumented `astro build` called
`compileRegistry` twice.
Deferring the first call does not help, because the two graphs never
share a module variable whenever it runs. Memoise on `globalThis`
instead, under a registered symbol, which is the one scope both graphs
agree on. An instrumented build now calls `compileRegistry` once.
Compiling the real registry takes about 2.6s and materialises 86397
references, so the second pass cost that time and a second copy in
memory on every build and every `dev` start.
Lifetime is unchanged: the process, exactly as the module memo was. A
`dev` server still needs a restart after the `data/` submodule changes.
Closes #131
Claude-Session: https://claude.ai/code/session_011HLhfpsrWxq56jnZr1gD8B
Co-authored-by: Moritz Mähr <14755525+maehr@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent 257f17e commit 4d1c708
2 files changed
Lines changed: 43 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
8 | 19 | | |
9 | 20 | | |
10 | | - | |
11 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
12 | 24 | | |
13 | 25 | | |
14 | 26 | | |
| |||
0 commit comments