Skip to content

perf(ocr): bound EasyOCR memory (skip Apple MPS, smaller detector canvas) - #23

Closed
Venopacman wants to merge 1 commit into
ayushh0110:mainfrom
Venopacman:perf/ocr-memory
Closed

Venopacman wants to merge 1 commit into
ayushh0110:mainfrom
Venopacman:perf/ocr-memory

Conversation

@Venopacman

Copy link
Copy Markdown
Contributor

Problem

On an Apple Silicon Mac (M5, 24 GB), the ScreenMind process used about 8.1 GB. About 7.5 GB of that was GPU memory: gpu=True makes EasyOCR use Apple's MPS backend, and PyTorch keeps that memory between frames.

Switching to CPU alone didn't help: peak was about 8.6 GB of normal RAM. The real cost is the CRAFT text detector running over the whole image at the default canvas_size=2560.

Fix

  • Use the GPU only when CUDA is available. NVIDIA users keep GPU OCR. Apple MPS is skipped.
  • Pass canvas_size=800 to readtext (OCR_CANVAS_SIZE). Recognition still reads crops from the full-resolution image, so most text survives.

Numbers

12 real 3024x1964 screenshots, CPU:

canvas_size Peak RAM Text kept Sec/frame
1920 7.7 GB 100% 7.8
1280 6.0 GB ~100% 2.5
960 4.0 GB 96% 1.9
800 3.1 GB 90% 1.7
640 2.1 GB 71% 1.1

The process went from about 8.1 GB to about 1.5 GB between frames. OCR is also faster than before (1.7s vs 3s per frame on MPS). It runs next to a model call of about 12s, so the speed doesn't matter much either way.

The 10% of text lost is mostly very short words (1–2 letters). If you'd rather trade memory for text, 960 keeps 96% at about 4 GB.

Testing

  • New tests: canvas_size reaches readtext, and _use_gpu() follows torch.cuda.is_available().
  • I couldn't test on a CUDA machine. The CUDA path itself doesn't change. Only the canvas size applies there too.

🤖 Generated with Claude Code

…vas)

On an Apple Silicon Mac the screenmind process held ~8 GB: EasyOCR's
gpu=True picks MPS, and PyTorch's MPS allocator kept ~7.5 GB of unified
memory between frames.

Moving to CPU alone did not help (peak ~8.6 GB of RAM). The cost is the
CRAFT detector running over the whole image at canvas_size=2560. Memory
scales with that size, while recognition still reads crops from the
full-resolution image. Measured on 12 real 3024x1964 screenshots, CPU:

  canvas  peak RAM  text kept  sec/frame
  1920    7.7 GB    100%       7.8
  1280    6.0 GB    ~100%      2.5
  960     4.0 GB    96%        1.9
  800     3.1 GB    90%        1.7
  640     2.1 GB    71%        1.1

- Use the GPU only when CUDA is available (NVIDIA users keep GPU OCR).
- Pass canvas_size=800 to readtext (OCR_CANVAS_SIZE).

Process footprint went from ~8.1 GB to ~1.5 GB between frames.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Venopacman

Copy link
Copy Markdown
Contributor Author

sorry - claude was too much initiative :D

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