Skip to content

perf: resolve frontend asset files from the runtime cache - #173

Merged
dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:perf/asset-cache
Oct 24, 2026
Merged

dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:perf/asset-cache

Conversation

@Contributolo

Copy link
Copy Markdown
Collaborator

Assets::parse_output() resolves every asset of every block on the page on disk for each uncached page view: glob() on the output directory, is_file(), filesize(), filemtime() and Runtime_Context::output_path() per asset, plus a recursive directory scan for CSS modules per block. On hosts with slow stat() (CageFS, network storage) this grows further.

The runtime cache already describes these files, and its watch snapshot covers the source and the compiled file. This PR records what the render path reads (resolved file, data-processed, size, both version keys) per asset, plus the CSS module files per block, when the build writes the runtime cache, after compiling and pruning the output directory. Cached requests read the records.

  • Asset data without a record keeps the disk lookup: cache disabled, live refresh, third-party render_tag() calls, and last-good payloads served while a peer rebuilds (their records may predate the changed sources, so they are dropped).
  • CSS module files join the watch snapshot and the required paths, so a removed file invalidates the cache like a removed compiled asset, also inside the debounce window.
  • URLs (blockstudio/files/url) and blockstudio/assets/disable are still resolved per request.
  • Output HTML is byte-identical on the three pages measured.

Measured on WordPress 7.1.3, PHP 8.4 with OPcache, 28 blocks, assets.output: cache, inlineLimit on. Forked in-process requests, ABAB, n=20 per run, medians:

Page assets metric before → after Total before → after
Home (6 blocks) 2.84 → 0.70 ms 50.7 → 49.1 ms
Page 2 0.94 → 0.46 ms 47.3 → 46.8 ms
Page 3 1.50 → 0.60 ms 50.2 → 49.2 ms

The runtime cache file grows by about 4% (50.9 → 53.0 KB).

Tests: AssetsTest (identical parse_output() with and without records, inline limit on and off; render_tag() reads a record without touching the disk; module styles), BuildCacheTest (module styles are watched and required).

parse_output() looked up every asset of every block on the page on disk
for each uncached page view: a glob() of the output directory, is_file(),
filesize() and filemtime() per asset, and a recursive directory scan for
CSS modules per block. The runtime cache already describes these files,
and its watch snapshot covers both the source and the compiled file.

The build now records what render_tag(), render_inline() and the inline
stylesheet limit read from disk (resolved file, data-processed, size and
the two version keys) on each asset, plus the CSS module files of each
block, after compiling and pruning the output directory. Cached requests
read these records. Asset data without a record (cache disabled, live
refresh, last-good payloads while a peer rebuilds, third-party callers)
keeps the disk lookup. CSS module files join the watch snapshot and the
required paths, so a removed file invalidates the cache like a removed
compiled asset. URLs and the disable filter are still resolved per
request.
@dnnsjsk

dnnsjsk commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Merged and released in Blockstudio 7.7.8, with the reviewed implementation and regression coverage. The release commit passed all 20 CI and distribution checks before publication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants