Rust: Dropping heavy things in another thread can make your code 10000 times faster

  • When working on Rust applications or CLIs that need to show something to the end user as fast as possible I often find that a significant chunk of the time is usually spent not in doing any computations, but in dropping large data structures at the end of the function.
  • This is because Rust needs to drop the value of a and deallocate all memory it was using before it can return.
  • This really sucks for UIs and interactive CLIs. We got all needed data to respond to a user request, but can't do anything with it until we finish cleaning things up!
  • The function returns right away and somewhere in the future the other thread will start doing the work of dropping the data structure and deallocating all used memory.

save | report | share on

Top 200 comments