Code size optimizations#257
Conversation
d5f003e to
5e30729
Compare
|
Really nice! We might want to hold off on the breaking changes though, since we probably want to wait a bit until releasing 0.2.0, so if you can split them into a separate PR that'd be great! |
|
Done! |
| match (#(&(#args)),*) { | ||
| (#(#pats),*) => { | ||
| let ts = defmt::export::timestamp(); | ||
| if let Some(mut _fmt_) = defmt::export::acquire() { |
There was a problem hiding this comment.
We could also make the acquire part of shared code, by doing something like:
impl Formatter {
pub fn start_frame(s: &Str) -> Option<Self> {
let ts = timestamp();
let mut fmt = acquire();
if let Some(fmt) = &mut fmt {
fmt.istr(s);
fmt.leb64(ts);
}
fmt
}
}As a bonus, this keeps the order of operations like it was before (timestamp, then acquire).
There was a problem hiding this comment.
Presumably we'd want to move the #[inline(never)] to start_frame, since we should only have a single call site to acquire remaining.
There was a problem hiding this comment.
Sounds like a good idea. What do we do with winfo! then? It needs to encode the header but doesn't create its own Formatter
There was a problem hiding this comment.
hmm, good question. Ideally I'd like to get rid of it. I might look into doing that tomorrow.
There was a problem hiding this comment.
I'll merge this PR as-is for now – we can always land further improvements later.
dyn Writewith an extraWritefunction in Logger trait. This saves quite a bit of space because now many Formatter methods no longer require access toself, which allows nice optimizations. -- MOVED from this PR into Replace Write trait with awritefn in Logger. #258timestampcall, then write the log string withistr, then write the timestamp withleb64. Extract this to a singleheaderfunction. Replaces 3 calls with 1, though most of the savings here come from#[inline(never)]because the compiler was inliningtimestamp.#[inline(never)]toacquireandreleasebecause the compiler was inlining them.With these changes, defmt code size goes from 62kb to 16kb In my project's firmware. This is a 73,8% code size reduction.
Generated code for this function:
Before:
After: