-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Code size #456
Comments
@Dirbaio: Thank you for putting in the effort to create this code size benchmark! Do we know which parts of the code contribute the most bloat? |
I've been experimenting with this. Code in my codesize4 branch, testbench updated.
This is at the cost of increasing the wire size, but:
Something I want to try next is to "pack" together multile write calls. For example when printing 4 u32s, instead of doing 4 write calls, put them in a 16-byte buffer then do a single 16-byte write call. I have a WIP version of this but it doesn't improve codesize that much. I'm still investing why. |
Updated table with size measurements from my company's firmware:
2x smaller! :) |
I've done a quick test with rzCOBS compression+framing. Results on
Wire size is better than upstream defmt, while keeping all the code size gains. Code size increase is only ~200 bytes. This is without needs_tag. Wire size could be even better if this is implemented. And it provides framing, so probe-run is able to recover from a corrupt stream! |
@Urhengulas @jonas-schievink what are your thoughts on this? Is this something you would want to address? #258 is an easy start, and I'm willing to clean/rework my other patches to PR them if you confirm this is something you'd like to review and merge. |
Personally I think this is a good change, inclusing plugging in rzCOBS, but we don't currently plan to make breaking changes to defmt, which complicates things. |
In what timeframe would you consider OK making the next breaking release? |
We currently want to avoid it, since it will split the ecosystem. We are discussing how to make breaking releases more feasible, mainly looking at #426. Another option we discussed is maintaining a |
Using defmt from git was extremely painful in the pre-0.1 times.
|
@Dirbaio do you have data on how much wire size is reduced for any of the 3 examples you posted in the last few tables? |
I think that would be the And the
|
Yeah, #525 should reduce the code size further but in its current state it didn't. In my original experiments branch it did reduce it quite a lot, so I still have to check what's up with that. Feel free to close this issue if you want. There'll always be some code size reduction possible, this'd stay open forever otherwise :P |
Okay, closing then! |
I have put together a code size testbench to measure code size. It has 2 test cases,
spam
logs lots of stuff (based on the qemu test) andsmoltcp
runs smoltcp's loopback example from latest git master (which has defmt support).spam
has 156 log calls and is 18428 bytes (.text size). Commenting therun_test()
call in main gives a .text size of 944 bytes. Therefore, defmt's code size is:Base size (RTT stuff, etc): 944 - 624 = 320 bytes
Log call size: (18428-944)/155 = 112.8 bytes/call
112.8 bytes/call sounds about right. As seen here, a simple
info!("defmt test {=u32}", x);
is already 74 bytes of code, and thespam
code does a mix of simple and complex log calls.And 112.8 bytes avg, or 74 bytes to print a u32 is A LOT.
For comparison, let's check good old C printf:
compiled with
arm-none-eabi-gcc -c printf.c -Os -mthumb
:This is just 8 bytes of code, or 8+14 = 22 bytes if we count the string.
Defmt is 3.5 times larger than printf when counting the string. And this is a generous comparison: arguably the apples-to-apples comparison is not counting the string, since the string pointer is equivalent to defmt's interned string IDs. In which case defmt is 10 times larger.
I'm aware defmt does much more than printf. It's to be expected a log call printing complex nested structs and enums generates bigger code. However, simple log calls (with no arguments or just a handful of integers) are the vast majority in real-world projects, and code size for these really hurts.
The text was updated successfully, but these errors were encountered: