Skip to content

Commit b20fc81

Browse files
authored
Rollup merge of rust-lang#125011 - diondokter:opt-for-size, r=Amanieu,kobzol
Add opt-for-size core lib feature flag Adds a feature flag to the core library that enables the possibility to have smaller implementations for certain algorithms. So far, the core lib has traded performance for binary size. This is likely what most people want since they have big simd-capable machines. However, people on small machines, like embedded devices, don't enjoy the potential speedup of the bigger algorithms, but do have to pay for them. These microcontrollers often only have 16-1024kB of flash memory. This PR is the result of some talks with project members like `@Amanieu` at RustNL. There are some open questions of how this is eventually stabilized, but it's a similar question as with the existing `panic_immediate_abort` feature. Speaking as someone from the embedded side, we'd rather have this unstable for a while as opposed to not having it at all. In the meantime we can try to use it and also add additional PRs to the core lib that uses the feature flag in areas where we find benefit. Open questions from my side: - Is this a good feature name? - `panic_immediate_abort` is fairly verbose, so I went with something equally verbose - It's easy to refactor later - I've added the feature to `std` and `alloc` as well as they might benefit too. Do we agree? - I expect these to get less usage out of the flag since most size-constraint projects don't use these libraries often.
2 parents dc3424e + 7b24df0 commit b20fc81

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

alloc/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ compiler-builtins-no-asm = ["compiler_builtins/no-asm"]
3737
compiler-builtins-mangled-names = ["compiler_builtins/mangled-names"]
3838
compiler-builtins-weak-intrinsics = ["compiler_builtins/weak-intrinsics"]
3939
# Make panics and failed asserts immediately abort without formatting any message
40-
panic_immediate_abort = []
40+
panic_immediate_abort = ["core/panic_immediate_abort"]
41+
# Choose algorithms that are optimized for binary size instead of runtime performance
42+
optimize_for_size = ["core/optimize_for_size"]

core/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ rand_xorshift = { version = "0.3.0", default-features = false }
3131
[features]
3232
# Make panics and failed asserts immediately abort without formatting any message
3333
panic_immediate_abort = []
34+
# Choose algorithms that are optimized for binary size instead of runtime performance
35+
optimize_for_size = []
3436
# Make `RefCell` store additional debugging information, which is printed out when
3537
# a borrow error occurs
3638
debug_refcell = []

std/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ system-llvm-libunwind = ["unwind/system-llvm-libunwind"]
7878

7979
# Make panics and failed asserts immediately abort without formatting any message
8080
panic_immediate_abort = ["core/panic_immediate_abort", "alloc/panic_immediate_abort"]
81+
# Choose algorithms that are optimized for binary size instead of runtime performance
82+
optimize_for_size = ["core/optimize_for_size", "alloc/optimize_for_size"]
8183

8284
# Enable std_detect default features for stdarch/crates/std_detect:
8385
# https://github.com/rust-lang/stdarch/blob/master/crates/std_detect/Cargo.toml

sysroot/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ llvm-libunwind = ["std/llvm-libunwind"]
2222
system-llvm-libunwind = ["std/system-llvm-libunwind"]
2323
panic-unwind = ["std/panic_unwind"]
2424
panic_immediate_abort = ["std/panic_immediate_abort"]
25+
optimize_for_size = ["std/optimize_for_size"]
2526
profiler = ["std/profiler"]
2627
std_detect_file_io = ["std/std_detect_file_io"]
2728
std_detect_dlsym_getauxval = ["std/std_detect_dlsym_getauxval"]

0 commit comments

Comments
 (0)