Live data from Hacker News

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

abramov.io

1–10 of 285 posts

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

#6

hmm my first thought its, having to do that is a lot like c and cleaning up my own allocations. This feels like something rust should automatically do for me?

In C, if you forget to clean up, you have a memory leak which is hard to track down. In Rust, if you don't do this, you're not sacrificing memory leaks, only performance. A profiler can tell you when you should drop asynchronously.

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

#7

Why would you ever write a get_size function that drops the object you call it on? Surely in an actual, non-contrived usecase spawning another thread and letting the drop occur there would just be plain worse?

Right there is no reason to pass ownership to a function like this.

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

#8
post #6

hmm my first thought its, having to do that is a lot like c and cleaning up my own allocations. This feels like something rust should automatically do for me?

In C, if you forget to clean up, you have a memory leak which is hard to track down. In Rust, if you don't do this, you're not sacrificing memory leaks, only performance. A profiler can tell you when you should drop asynchronously.

>A profiler can tell you when you should drop asynchronously

Is there any profiler that does this today?

What are the drawbacks with asynchronous drops?

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

#10
post #5

I'm not very familiar with Rust, but I don't understand why you wouldn't just use a reference-to-HeavyThing as the function argument, so that the object isn't moved and then dropped in the `get_size` function?

For these contrived cases, yes, you would just pass a reference to the function but I think the point is to simplify the case down to demonstrate a point.
Post reply on HN