
How a "Simple" QR Code Generator Ate All My RAM: A Tale of 50,000 QR Codes
Sometimes the simplest tasks can become the biggest headaches. Here's how I learned that data size matters more than code complexity. The Innocent Beginning It started with a straightforward request: generate 50,000 unique QR codes for a project. "How hard could it be?" I thought. Python has excellent libraries for this. A quick script, a PDF output, done by lunch. I was wrong. Very wrong. What I didn't anticipate was that my "simple" script would consume every byte of RAM on my machine, freeze my computer, and teach me an important lesson about thinking at scale. Let me walk you through what happened, how I fixed it, and what you can learn from my mistakes. The Original Approach: Looks Good on Paper Here's the approach I initially took. Generate all the QR codes first, cache them in memory, then write them to a PDF. It sounds logical, right? Pre-compute everything, then assemble the final output. def generate_pdf ( output_path : str , total : int = 50000 ): ids = generate_unique_ids (
Continue reading on Dev.to Python
Opens in a new tab



