The internal representation of String is Vec<u8>
, but vec.truncate
loops to drop members.
Perhaps setting the length directly?
Maybe vec.truncate
could use std::intrinsics::needs_drop::<T>()
to decide if the loop is needed?
It's already optimized out when optimizations are enabled. These loops could use needs_drop
to improve performance when optimizations are disabled, but I don't think it's very important.
vec.truncate
leads to 70% decreased performance in some cases for game development, where compiling with optimization has negative impact on productivity.
@bvssvni Even just O1 isn't reasonable for development?
It would be nice if adding a profile to Cargo.toml was not required for a such simple case.
Would it make sense to have cargo default to O1?
@rust-slacker: LLVM only fully supports debugging at -O0
, unlike GCC which supports it at all optimization levels via a lot of work integrating support in passes.
Closing; I don't think we necessarily want to do this.
Fun fact: I may or may not have spent a few hours banging my head against performance issues that ultimately were resolved by replacing a truncate with a set_len. (See this commit)
Yeah, I know the optimizer is supposed to handle it, and in a perfect world that would be it, but...
Most helpful comment
Fun fact: I may or may not have spent a few hours banging my head against performance issues that ultimately were resolved by replacing a truncate with a set_len. (See this commit)
Yeah, I know the optimizer is supposed to handle it, and in a perfect world that would be it, but...