Skip to content

Improve custom-host HTML minification performance while preserving output semantics #1371

Description

@ryoppippi

Measured optimisation opportunity

After removing embed rendering from client island discovery (see #1370), the custom-host closeBundle phase remains around 3 seconds on ryoppippi.com with @ox-content/vite-plugin 3.1.1. Temporary timing probes identify HTML minification as a measurable part of this cost; this is an optimisation request, not evidence of a particular regression.

Warm local build, 402 client modules and 428 custom-host outputs:

Phase Observed duration
Host loader server 25–41 ms
Load host module 141–168 ms
Load/prepare routes 1.42–1.56 s
Render routes 169–253 ms
Output planning 157 ms
Self-hosted assets 119 ms
HTML minify + writes 573 ms
Loader shutdown 251–371 ms

An A/B run changing only custom-host build.minifyHtml:

  • Enabled: coordinated output writer 974 ms; complete pnpm exec vp build subprocess wall time 4902 ms.
  • Disabled: coordinated output writer 389 ms; subprocess wall time 4123 ms.
  • Vite client build remained about 0.75–0.77 s.

These are single-machine diagnostic measurements, not a controlled multi-run benchmark. The writer difference is about 585 ms; total process time also varies in other stages. Production minification remains enabled; disabling it is only an experimental control.

Current implementation

Verified current source: https://github.com/ubugeeei-prod/ox-content/blob/main/npm/vite-plugin-ox-content/src/html-minify.ts

minifyHtmlOutput uses html-minifier-terser with Terser and clean-css callbacks. The custom-host output writer invokes it for every generated HTML route. Promise.all over route writes does not itself move JavaScript CPU work off the main thread.

Request

Please profile/optimise this production path while preserving the existing semantic guarantees, including hydration comments, whitespace, embedded JS/CSS and error handling. Potential approaches to evaluate include reuse of identical inline-script/style minification results within a build, or a faster compatible backend. These are investigation suggestions, not verified fixes.

A public supported fast path would let downstream custom hosts retain production output quality while reducing total SSG build time. Reproduce using a custom-host site with dozens of HTML pages, transformHtml: false, and minifyHtml: true; compare writer/total timings with minification disabled.

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions