Description
At the moment, using debug assertions is discouraged because it will hurt performance. In practice, no one disables assertions so they are not used: debug_assert!
only has 11 uses in the Rust repository. It would have many more if I didn't feel I had to delete all of the assertions I used during development to avoid a 5-20% performance hit by default.
It would make a lot more sense to enable them by default only in non-optimized builds where the performance hit will be dwarfed by other issues. It would be overridden by passing an explicit --cfg
switch, and Rust's build system could just use the default. Rust developers could easily override this, but users and packagers wouldn't be given a slow / bloated build by default.
This would make it acceptable to use debug_assert!
for bounds checks in the unchecked indexing methods on slices and the very valuable jemalloc debugging assertions could also be enabled by default in an unoptimized build. Using the debug variant of mutexes rather than faster deadlocking ones is another example. There are bots building and testing with no optimizations, so there would be better testing coverage.