Skip to content

perf(translate): remember BabelDOC font hash passes - #131

Merged
TranBaDat2607 merged 1 commit into
mainfrom
feat/font-verify-cache
Oct 21, 2026
Merged

TranBaDat2607 merged 1 commit into
mainfrom
feat/font-verify-cache

Conversation

@TranBaDat2607

@TranBaDat2607 TranBaDat2607 commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Why

BabelDOC builds a FontMapper in every pipeline stage (7 per page on Argos, 8 on the LLM path), and each one runs assets.verify_file over all 34 target-language fonts — 266 MB of SHA3-256, ~1 s — against the same unchanged files.

What

  • processors/font_verify_cache.py: memoizes babeldoc.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: the engine-warm thread pre-verifies fonts already on disk (preverify_cached_fonts) — reads only, never downloads, own try so it can't cost the layout-model warm-up.
  • api/routes/translation.py: _load_engine installs the memo too, for a Translate click that beats the warm thread (idempotent).
  • Docs: translation-pipeline.md updated 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:

memo off memo on
run 1 27.9 s 17.4 s
run 2 28.4 s 16.5 s
run 3 28.1 s 16.1 s
avg 28.1 s 16.7 s (−40%)
real font hashes 613 64–67

(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 to done, after one warm-up run filled the paragraph cache:

main this branch
run 1 26.6 s 13.8 s
run 2 26.9 s 14.4 s
run 3 26.4 s 14.6 s
avg 26.6 s 14.3 s (−46%)

All runs ended done. The warm thread logged BabelDOC 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.
  • Not exercised: the frozen sidecar.

🤖 Generated with Claude Code

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
TranBaDat2607 force-pushed the feat/font-verify-cache branch from 5d7d067 to ce84950 Compare October 21, 2026 10:30
@TranBaDat2607
TranBaDat2607 merged commit a7358d9 into main Oct 21, 2026
6 checks passed
@TranBaDat2607
TranBaDat2607 deleted the feat/font-verify-cache branch October 21, 2026 10:31
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.

1 participant