pyronear / pyronear/pyro-annotator
API process loads onnxruntime/cv2 unnecessarily via worker import chain
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 0
- Forks
- 1
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 2
Description
Follow-up from #162 (detection-review chunk 1).
Problem
app/main.py imports from app.worker import app as procrastinate_app (needed to open the procrastinate connector in the FastAPI lifespan). app/worker.py in turn does from app.services.smoke_detector import SmokeDetector, and smoke_detector.py imports cv2, onnxruntime, and numpy at module top.
Net effect: the API (uvicorn) process loads onnxruntime + cv2 at startup even though it never runs inference — only the worker process does. This costs ~100 MB RAM and slower startup on the API container for zero benefit.
Suggested fix
Split the lightweight procrastinate App handle out of the heavy task module:
app/queue.py(or similar): justapp = App(connector=PsycopgConnector(...))— no heavy imports.main.pyand the enqueue endpoint import theApp/ task from there.- Keep the
SmokeDetectorimport (and the@app.taskbody that uses it) in the worker task module, which only theprocrastinate workerprocess loads.
This keeps onnxruntime/cv2 out of the API process while preserving the "imports at top" convention (no lazy/inline imports).
Notes
- Not a correctness bug — purely a resource/startup-time cost.
- ~15-line refactor touching module structure.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with app/main.py, app/worker.py, and app/services/smoke_detector.py to trace the current App and SmokeDetector imports. Then inspect the enqueue endpoint and the task definition before separating the lightweight App handle into app/queue.py or a similar module. Done means the API process no longer loads onnxruntime or cv2, while the worker still imports SmokeDetector and runs its task.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend, performance
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100