Skip to content

perf: reuse isolated OCR runner - #394

Merged
suguanYang merged 5 commits into
mainfrom
perf/wangbinqi/isolate-ocr-worker
Sep 8, 2026
Merged

suguanYang merged 5 commits into
mainfrom
perf/wangbinqi/isolate-ocr-worker

Conversation

@suguanYang

@suguanYang suguanYang commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • keep one spawned OCR child alive for the ocr.pages call
  • load RapidOCR once and process pages sequentially through a request/response queue
  • cap ONNX Runtime to one intra-op and one inter-op thread
  • restart the child on timeout/crash and preserve per-page OCR output

Motivation

The previous version isolated OCR but restarted the process/model for every page. This version keeps CPU bounded while avoiding repeated model initialization. Only one OCR request is in flight at a time, so a 70-page scan may be slow but does not fan out OCR CPU work.

Verification

  • uv run pytest -q tests/contract/test_ocr_pages_contract.py tests/contract/test_doc_profile_anatomy_contract.py — 29 passed
  • uv run ruff check app/services/document_agent/tools/ocr_pages.py tests/contract/test_ocr_pages_contract.py
  • real spawn smoke test: one persistent child processed two pages successfully

The local reproduction PDF was not committed.

@suguanYang suguanYang changed the title perf: run scanned OCR one page at a time perf: reuse isolated OCR runner Sep 8, 2026
Comment thread apps/worker/app/services/document_agent/tools/ocr_pages.py Fixed
Comment thread apps/worker/app/services/document_agent/tools/ocr_pages.py Fixed
suguanYang and others added 2 commits September 8, 2026 21:14
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@suguanYang
suguanYang merged commit c35cf58 into main Sep 8, 2026
6 checks passed
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