-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow opting out of specific parts of core crate (e.g. core::fmt) #3665
Comments
We have begun exploring allowing size-based optimizations based on |
Those optimizations might save a few dozen KiB, but I don't see them shrinking the code size below 8KiB. Adding the ability to opt out of parts of core should be a fairly small change to the language which requires less effort than making optional size optimizations in core. |
people still use Arduino ATtiny85s? I figured they had all moved on to, like, Teensys by now. |
I'm using 8KiB as an example because I saw a thread somewhere of someone having issues with not being able to get their code below that size when their job required it. Also, people can't just say "but there's new hardware" every time someone has issues with resource usage, otherwise code will only become more inefficient. |
I suppose the ATmega line and STM32s are "new" on some timescale... Talking about "efficiency" is a distraction. Space and time generally trade against each other. More recent processors often compute more efficiently, even more efficiently than microcontrollers, if you factor in how much work they get done, which would take more time for the microcontroller and thus potentially more energy. Anyways, the problem is that your example with the smaller binary... exists. It works because it doesn't use code that wants to link against the formatting code. So simply declaring portions "unused" which nonetheless would want to be linked in has a slight problem: how do you handle the name resolution errors? |
If the answer is "somehow the rest of libcore would magically adapt to the exclusion" then it seems you have arrived at another, even-more-aggressive |
Give an error saying that part of libcore depends on the excluded portion. |
that demand occurs instantly upon building libcore, however. |
I’m not an embedded developer, but my understanding is that this is often infeasible. There can be multiple reasons:
By building libcore without the calls to |
Which is not implementable as |
@workingjubilee It is implementable as |
In embedded systems development, there's usually a small maximum binary size. (e.g. 8KiB).
The size of core::fmt when compiled into the executable is too big for this.
Take a freestanding,
x86_64-unknown-none
,panic="abort"
executable with 3 functions: A panic handler, a function namedpanik
, and the_start
function. In both thepanic
andpanik
functions, the only expression isloop {unsafe {asm!("hlt");}}
. In the_start
function, the only expression is eitherpanic!();
orpanik();
If you run
cargo bloat --release --target=x86_64-unknown-none
on the program's source when the only expression in_start
ispanic!();
, the resulting executable size is 665.4KiB, which is 83 times the hypothetical size limit of our executable.However, if you run the same command when the function in
_start
used ispanik();
, the executable size is now only 1.8KiB, which is only 25% of the limit: 332 times smaller.It would be very nice if we could opt out of using parts of core like
core::fmt
instead of struggling to avoid compiling it. When opted out of part of core, the compiler will output an error (E0412) upon compiling something that is in or depends on the opted out portion, instead of silently compiling it in. My suggestion for the syntax isunuse core::foo::bar;
, though other syntax is fine.The text was updated successfully, but these errors were encountered: