Hacker News new | ask | show | jobs
by Ygg2 2245 days ago
It's a tradeoff. Do you want your code to run as if it was written by hand (i.e. duplicated by hand)? Then monomorphization is best.

For Rust, it makes a lot of sense to pay for some compile speed penalty to not have any performance penalty.

2 comments

> during development builds

That's the key phrase in his statement.

I'm not familiar with Rust, but if compilation speed is a major issue, and there are aspects of the compilation that are avoidable to trade-off for runtime performance, it seems to be a good idea to make those configurable per-build-type. Does Rust not offer this?

I've written an image processing tool in Rust, where running a large image downscaling test with a release build takes 2.0 seconds, and with a debug build it takes 18.7 seconds. So most of the time during development I compiled in release mode, because it was actually faster overall.

For many applications debug builds are fast enough, but their runtime performance is already so slow, that I hope they don't get even slower.

It could certainly be a config flag on the profile that can be optionally enabled, and wouldn't need to be enabled by default.
Not currently, but it's been discussed a few times. Nobody has tried to write a patch yet, that I'm aware of.
> Do you want your code to run as if it was written by hand (i.e. duplicated by hand)? Then monomorphization is best.

That's not always true because monomorphization where the vast majority of the object code is the same in all actual cases means bloating the text of the program, which means putting pressure on the Icache, which means more cache misses, which... is slow.