Rust: Dropping heavy things in another thread can make your code 10000x faster
Some important things I think people should note before blindly commenting:<p>* The example code is obviously contrived.  The real gist is that massive deallocations in the UI thread cause lag, which the example code proves.  That very thing can easily happen in the real world.<p>* I didn't see any difference on my machine between a debug build and a release build.<p>* The example is preforming 1 _million_ deallocations.  That's why it's so pathological.  It's not just a "large" vector.  It's a vector of 1 million vectors.  While that may seem contrived, consider a vector of 1 million strings, something that's not too uncommon, and which would likely suffer the same performance penalty.<p>* Rust is not copying anything, nor duplicating the structures here.  In the example code the structures would be moved, not copied, which costs nothing.  The deallocation is taking up 99% of the time.<p>* As an aside, compilers have used the trick of not free-ing data structures before, because it provides a significant performance boost.  Instead of calling free on all those billions of tiny data structures a compiler would generate during its lifetime, they just let them leak.  Since a compiler is short lived its not a problem, they get a free lunch (pun unintended), and the OS takes care of cleaning up after all is said and done.  My point is that this post isn't theoretical, we do deallocation trickery in the real world.