Skip to content

Commit

Permalink
Avoid an unnecessary use of SmallStr.
Browse files Browse the repository at this point in the history
I don't know why `SmallStr` was used here; some ad hoc profiling showed
this code is not that hot, the string is usually empty, and when it's
not empty it's usually very short. However, the use of a
`SmallStr<1024>` does result in 1024 byte `memcpy` call on each
execution, which shows up when I do `memcpy` profiling. So using a
normal string makes the code both simpler and very slightly faster.
  • Loading branch information
nnethercote committed Jun 29, 2023
1 parent 45fcd1d commit de1914a
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Set and unset common attributes on LLVM values.

use rustc_codegen_ssa::traits::*;
use rustc_data_structures::small_str::SmallStr;
use rustc_hir::def_id::DefId;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::ty::{self, TyCtxt};
Expand Down Expand Up @@ -481,8 +480,8 @@ pub fn from_fn_attrs<'ll, 'tcx>(

let global_features = cx.tcx.global_backend_features(()).iter().map(|s| s.as_str());
let function_features = function_features.iter().map(|s| s.as_str());
let target_features =
global_features.chain(function_features).intersperse(",").collect::<SmallStr<1024>>();
let target_features: String =
global_features.chain(function_features).intersperse(",").collect();
if !target_features.is_empty() {
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "target-features", &target_features));
}
Expand Down

0 comments on commit de1914a

Please sign in to comment.