QR Code 성능: 생성 및 스캔 속도
Optimising QR code generation and scanning speed: library benchmarks, caching, image preprocessing, and hardware acceleration.
QR Code Performance: Generation and Scanning Speed
Optimising QR code generation and scanning speed matters for high-traffic APIs, real-time applications, and mobile scanning experiences.
Generation Benchmarks
Approximate generation times (single QR code, module count." data-category="QR Code Structure">Version 5, EC-M):
| Library | Language | Time | Notes |
|---|---|---|---|
| segno | Python | 0.5 ms | Pure Python, fastest Python option |
| qrcode | Python | 2-5 ms | With pillow PNG output |
| go-qrcode | Go | 0.1 ms | Compiled, very fast |
| qrcode-rs | Rust | 0.05 ms | Fastest overall |
| ZXing | Java | 1-3 ms | JVM warm-up affects first call |
Optimising Generation Speed
Caching: The most impactful optimisation. Cache generated QR code images keyed on a hash of the input data:
import hashlib
from functools import lru_cache
@lru_cache(maxsize=10000)
def get_qr_image(data: str, ec: str = "m") -> bytes:
qr = segno.make(data, error=ec)
buffer = io.BytesIO()
qr.save(buffer, kind="png", scale=8)
return buffer.getvalue()
Pre-generation: Generate QR codes at data creation time (not at request time).
SVG over PNG: SVG generation skips pixel rendering, reducing time by 50-80%.
Reduced scale: Generate at the minimum viable resolution.
Scanning Speed Optimisation
For mobile and web-based scanning:
- Reduce video resolution: 720p is sufficient for QR detection (1080p/4K is wasted)
- Throttle frame processing: Process every 3rd-5th frame (10-15 fps effective scan rate)
- Region of interest: Only process the centre portion of the camera feed where the QR code is likely positioned
- Hardware acceleration: Use platform-native APIs (Vision on iOS, ML Kit on Android) rather than pure-JavaScript decoders
Image Preprocessing
For batch decoding of QR code images:
- Convert to greyscale first (skip RGB processing)
- Apply bilateral filter for noise reduction without edge blurring
- Adaptive thresholding for binarisation
- Crop to the QR code region if position is known
Key Takeaways
- Caching is the single most impactful generation optimisation
- Go and Rust libraries are 10-50x faster than Python for raw generation
- SVG output is 50-80% faster than PNG (no pixel rendering)
- Reduce camera resolution and frame rate for scanning efficiency
- Platform-native scanning APIs outperform JavaScript decoders