Page-level HTML build cache backed by HF storage buckets - #800
Merged
Conversation
Building the HTML docs of a large library (transformers: ~400 en pages,
14 + 18 min per main build) prerenders every page even when a commit
changed one of them. This adds an opt-in page-level cache
(--html_page_cache <hf://buckets/...|local dir>) so the SvelteKit build
only prerenders pages whose content actually changed:
- key = sha256(generated mdx, kit tree hash, package, language,
doc-builder version). Keying on the post-autodoc, post-link-resolution
mdx means docstring changes invalidate exactly the affected pages.
- keys are version-normalized: resolved internal links embed
/docs/{pkg}/{version}/{lang}/, which would make otherwise-identical
pages differ between main and pr_N builds. On a cross-version reuse,
page URLs are rewritten to the target version while asset URLs stay
pinned to the source version (its content-hashed assets remain hosted
by the additive doc bucket; chunk-to-chunk imports resolve relative to
the chunk's own URL).
- storage: manifest per (package, language) + content-addressed blobs,
over a local dir or an HF storage bucket via huggingface_hub.
- cache failures are never fatal (degrade to building the pages).
- shared workflows: main builds read+write the hf-doc-build/
doc-build-cache bucket; PR builds are read-only (no secrets, public
bucket), so untrusted code cannot poison the cache.
Verified on the accelerate e2e (local dir and a real bucket):
cold populates 48 pages with output byte-identical to an uncached build;
warm reuses 46/48 (the 2 misses are the docstring pages containing
nondeterministic python object addresses - correct invalidation);
single-file change rebuilds exactly that page, mixed output equivalent
to a full fresh build; cross-version (--version pr_5) reuses 35/48 with
page links rewritten to pr_5 and all asset refs pinned to main.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Doc builds prerender every page even when a commit changed one file (transformers: ~400 en pages, 14 min + 18 min for other languages per main build, ~5 min of which is re-uploading pages that didn't meaningfully change). This adds an opt-in page-level HTML cache stored in an HF storage bucket:
Design
sha256(generated mdx ‖ kit tree hash ‖ package ‖ language ‖ doc-builder version). Keying on the generated mdx (post autodoc + internal-link resolution) means docstring changes from library code invalidate exactly the affected pages, and any kit/dependency change invalidates everything./docs/{pkg}/{version}/{lang}/, which would make otherwise-identical pages differ betweenmainandpr_Nbuilds. Keys normalize that segment, and on a cross-version reuse the page URLs are rewritten to the target version while asset URLs stay pinned to the source version — its content-hashed assets remain hosted (the doc bucket sync is additive) and chunk→chunk imports resolve relative to the chunk's own URL, so apr_Npreview page can safely loadmain's assets. Autodoc pages self-exclude from cross-version reuse (their GitHub source links embed version tags/line numbers).(package, language)plus content-addressed HTML blobs; backends are a local directory (tests/local builds) or an HF bucket viahuggingface_hub's bucket APIs.HF_TOKEN) and read-only on PR builds (which run without secrets against the public bucket) — untrusted PR code cannot poison pages that trusted builds would reuse.The
hf-doc-build/doc-build-cachebucket has been created (public).Verification (accelerate e2e, local dir and a real bucket)
<object object at 0x…>addresses, i.e. correct invalidation--version pr_5pr_5and all 15 asset refs pinned tomain; misses = the 11 autodoc pages + 2 nondeterministichf://buckets/mishig/doc-cache-testAlso:
pytest(incl. newtests/test_build_cache.py),ruff check/formatclean.Expected CI impact
Sync to bucketstep (280 s today) also collapses since reused pages are byte-identical.Follow-ups worth considering: a periodic GC job for old blobs (bucket
rmby age), and extending the cache to the python conversion stage.🤖 Generated with Claude Code