Repository navigation
perf(translate): remember BabelDOC font hash passes - #131
Merged
Merged
Conversation
BabelDOC re-hashes all 34 target-language fonts (266 MB) in every pipeline stage, 7-8 times per page. Memoize assets.verify_file on passes only, tied to size+mtime, and pre-verify cached fonts on the engine-warm thread. 3-page Argos run: 28.1 s -> 16.7 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TranBaDat2607
force-pushed
the
feat/font-verify-cache
branch
from
October 21, 2026 10:30
5d7d067 to
ce84950
Compare
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.
Why
BabelDOC builds a
FontMapperin every pipeline stage (7 per page on Argos, 8 on the LLM path), and each one runsassets.verify_fileover all 34 target-language fonts — 266 MB of SHA3-256, ~1 s — against the same unchanged files.What
processors/font_verify_cache.py: memoizesbabeldoc.assets.assets.verify_file. Only a pass is remembered, keyed on (path, expected hash) and tied to the file's size + mtime before and after hashing — a failure, a re-downloaded font, or a file changed mid-hash is checked again. Nothing persists across processes.api/server.py: theengine-warmthread pre-verifies fonts already on disk (preverify_cached_fonts) — reads only, never downloads, owntryso it can't cost the layout-model warm-up.api/routes/translation.py:_load_engineinstalls the memo too, for a Translate click that beats the warm thread (idempotent).translation-pipeline.mdupdated with the measurements and the rules.Measured
3 pages of
attention.pdf, en→vi, Argos, fresh process per run, paragraph cache pre-warmed, whole-PDF cache bypassed:(64–67 rather than 34: two parallel Argos chunks both hash before either records a pass — no single-flight; the warm-thread pre-check covers that in the app.)
In the app (
pnpm tauri dev)Same 3 pages, en→vi, Argos,
bypass_cache: true, driven through the running app's sidecar (POST /translate+ the events stream — the call the Translate button makes), timed todone, after one warm-up run filled the paragraph cache:mainAll runs ended
done. The warm thread loggedBabelDOC fonts pre-verified: 34 of 34 on disk passed in 1.0s; engine warm-up went 4.1 s → 6.0 s, off the click path. The translated output was not inspected visually.Tests
tests/test_font_verify_cache.py(memo rules + one integration test against the real babeldoc hook point),tests/test_engine_warm_gate.py(warm-up wiring).pytest tests: 1401 passed, 8 skipped.ruff check: clean.🤖 Generated with Claude Code