Workflow · Production

Memory-efficient image passing in Dropbox's iOS document scanner

The problem

The iOS document scanner pipeline caused large memory spikes by requiring a pixel copy at each processing stage via UIImage, leading to out-of-memory process terminations on device.

First attempt

Apple's UIImage container was unsuitable for a multi-stage image processing pipeline because it forced a pixel copy at each stage, generating excessive memory overhead and contributing to out-of-memory crashes.

Workflow diagram · grounded in source
1
Camera image capture
trigger
“the iOS camera gives us a UIImage, which is internally backed by a JPEG encoding”
2
Multi-stage scanner pipeline
ai_action
“the input image goes through resizing, document detection, rectification, enhancement and then compression, among other things”
3
Output image produced
output
“do something with output, e.g. display, upload or store”
Reported outcome

Replacing UIImage with a custom DBPixelBuffer class reduced memory spikes from 60MB to 40MB and cut peak memory usage by more than 50MB, improving scanner stability.

Reported metrics
Memory spike peakfrom 60MB to 40MB
Peak memory usage reductionmore than 50MB
Reported stack
UIImageDBPixelBufferlibjpeg
Source
https://dropbox.tech/machine-learning/memory-efficient-image-passing-in-document-scanner
Read source ↗

Frequently asked questions

What did this team achieve with this AI workflow?

Replacing UIImage with a custom DBPixelBuffer class reduced memory spikes from 60MB to 40MB and cut peak memory usage by more than 50MB, improving scanner stability.

What tools did this team use?

UIImage, DBPixelBuffer, libjpeg.

What results were reported?

Memory spike peak: from 60MB to 40MB; Peak memory usage reduction: more than 50MB (source-reported, not independently verified).

What failed first in this deployment?

Apple's UIImage container was unsuitable for a multi-stage image processing pipeline because it forced a pixel copy at each stage, generating excessive memory overhead and contributing to out-of-memory crashes.

How is this workflow AI workflow structured?

Camera image capture → Multi-stage scanner pipeline → Output image produced.