4 ms·
The length Rust programmers will go to avoid writing `Box<dyn Trait>` is astonishing. The heap is there for a reason :)
by selfmodruntime 1y ago
The length Rust programmers will go to avoid writing `Box<dyn Trait>` is astonishing. The heap is there for a reason :)
- alfiedotwtf 1y agoI’m guilty of this… I’ve doing using Rust for 10 years, and I’ve only ever used `Box<dyn>` maybe 4 times all up. .. yep, I’ll try everything before introducing virtual functions just out of warm fuzzies rather than anything measurable
- ccleve 1y agoThe performance hit you take for doing dynamic dispatch is real and measurable. It's a no-go if you're in a performance sensitive part of your app.
- selfmodruntime 1y agoI write rust for no_std embedded devices and I just use stack_dst for this :) Of course you‘re right if you can‘t alloc, you can‘t use Box or similar stuff. Also you can avoid a lot of performance hits if you just implement most stuff on the dyn Trait directly!
- surajrmal 1y agoSure but most code paths are not hot. This is definitely premature optimization at the expense of everything else.