Comment

Comment by misrasaurabh1

I've been running into performance bottlenecks in the wild where `copy.deepcopy()` was the bottleneck. After digging into it, I discovered that deepcopy can actually be slower than even serializing and deserializing with pickle or json in many cases!

I wrote up my findings on why this happens and some practical alternatives that can give you significant performance improvements.

*TL;DR:* deepcopy's recursive approach and safety checks create memory overhead that often isn't worth it. The post covers when to use alternatives like shallow copy + manual handling, pickle round-trips, or restructuring your code to avoid copying altogether.

Has anyone else run into this? Curious to hear about other performance gotchas you've discovered in commonly-used Python functions.

parent misrasaurabh1 11 months ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton