perf(bbox-worker): refine a multi-document extraction's documents concurrently (26.6.14)#39
Merged
Merged
Conversation
…currently (26.6.14) The bbox-refine post-processing leg refined documents in a strictly sequential `for` loop, so a cross-document extraction paid the sum of every document's OCR + per-page-matcher latency. A 5-document, ~290-page job ran ~700s and blew the 600s `bbox_refine_timeout_s`, timing out on all three attempts and re-doing every document from scratch each retry. Documents are independent (each mutates its own `field_groups`) and the refiner already offloads its CPU-bound word collection to a thread, so the leg now fans out one task per document through a bounded `asyncio.gather`. Wall-clock drops from the sum of per-doc latencies to ~the slowest one. - New `FLYDOCS_BBOX_REFINE_DOC_CONCURRENCY` (default 4) caps the fan-out: OCR is CPU-bound and each doc multiplies in-flight LLM calls. - `gather` is the barrier that keeps "the last document finished" well-defined — the completion transition + post-processing webhook fire exactly once, after every document has settled. - Error semantics unchanged: one document's failure still fails the leg (via `return_exceptions=True` + re-raise), leaving no sibling task running mid-flight. Tests: concurrency happens, is capped by the setting, completion waits for every document, and a single-document failure fails the job without stranding siblings.
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.
Fans out the per-document bbox refine of a multi-document extraction with a bounded
asyncio.Semaphore+gatherinstead of refining one document at a time.bbox_refine_doc_concurrency(envFLYDOCS_BBOX_REFINE_DOC_CONCURRENCY, default 4) bounds the fan-out; size it to the bbox-worker pod CPU limit.gatheris the barrier so the completion + webhook fire exactly once after every document settles;return_exceptions=Truethen re-raises the first error (preserves retry/permanent-failure semantics).Bumps version to 26.6.14.