perf: parallelize HTTP OCR batch requests#93
Open
AdemBoukhris457 wants to merge 1 commit intorun-llama:mainfrom
Open
perf: parallelize HTTP OCR batch requests#93AdemBoukhris457 wants to merge 1 commit intorun-llama:mainfrom
AdemBoukhris457 wants to merge 1 commit intorun-llama:mainfrom
Conversation
recognizeBatch() used await in a for loop, processing images sequentially. Replace with Promise.all to send all HTTP requests concurrently, consistent with the Tesseract engine implementation.
| results.push(result); | ||
| } | ||
| return results; | ||
| return Promise.all(images.map((image) => this.recognize(image, options))); |
Contributor
There was a problem hiding this comment.
Uhh if its a 400 page document this will send 400 requests. Most will timeout unless the user has a production-level deployment that scales
Contributor
There was a problem hiding this comment.
I think a better fix here is limiting to --num-workers ? Even then not great, but at least its controllable
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.
Summary
Promise.allinHttpOcrEngine.recognizeBatch()to send all HTTP OCR requests concurrently.Problem
recognizeBatch()insrc/engines/ocr/http-simple.tsprocesses images one at a time usingawaitin aforloop. HTTP OCR servers can handle concurrent requests, so this unnecessarily serializes work. With 10 images at ~500ms each, sequential takes ~5s vs ~500ms in parallel.The Tesseract engine's
recognizeBatch()already usesPromise.allfor parallel processing. The HTTP engine was inconsistent.Changes
src/engines/ocr/http-simple.ts: Replace sequential loop withPromise.all(images.map(...)), matching the Tesseract engine's implementation.Closes #92