3 ms·
I’m actually very curious why it takes this long; is Rust memseting the buffer when dropping it? Edit: it seems like turning on optimizations seems to improve
by saagarjha 6y ago
I’m actually very curious why it takes this long; is Rust memseting the buffer when dropping it?
Edit: it seems like turning on optimizations seems to improve the situation quite a bit. Not sure why they were profiling the debug build.
- deleted 6y ago[deleted]
- firethief 6y ago> Edit: it seems like turning on optimizations seems to improve the situation quite a bit. Not sure why they were profiling the debug build. This is the most important point in the thread, since it invalidates the results for most purposes.
- saagarjha 6y agoNot completely, it's still 2-3 orders of magnitude slower.
- firethief 6y agoYou're right, I expected it would make a bigger difference
- dathinab 6y agoThe thing is it's not slow because rust is doing anything wrong or unoptimized, is slow because cleaning up insane amounts of memory allocations is slow. Also if you run this: ``` fn main() { ::std::thread::spawn(move || { println!("end")}); println!("Hello, world!"); } ``` You might notice that "end" might not be printed because the main thread exists before it prints and terminates the process. This means that the dropping might actually not happen if it's at the end of the program and nothing is faster then not doing the work. Also it's a not uncommon pattern in small user facing CLI to leak (memory) resources, as they (should) be cleaned up with the process termination.
- Reelin 6y ago> I’m actually very curious why it takes this long; is Rust memseting the buffer when dropping it? Regardless of memset and optimizations, consider a particularly complicated object which lives on the heap and contains hundreds of other nested objects (which themselves contain nested objects, etc). Now imagine that a significant fraction of them make use of RAII. That cleanup code can't be elided. That being said, it's a pretty bad example if they were actually profiling the debug build ...
- fpgaminer 6y ago> it seems like turning on optimizations seems to improve the situation quite a bit. I'm not seeing that on my local machine? Were you comparing on the Playground which would be quite variable in its results? > cargo build Compiling foo v0.1.0 (/private/tmp/foo) Finished dev [unoptimized + debuginfo] target(s) in 0.42s > ./target/debug/foo drop in another thread 52.121µs drop in this thread 514.687233ms > > > cargo build --release Compiling foo v0.1.0 (/private/tmp/foo) Finished release [optimized] target(s) in 0.47s > ./target/release/foo drop in another thread 48.418µs drop in this thread 548.005373ms
- saagarjha 6y agoI saw an increase of about 2x on my computer, though I didn't take too much effort to control for noise.