pw_async2: Reduce code size for coroutine allocation http://pwrev.dev/42995 fixed a bug encountered with a newer LLVM toolchain. However it was was written with a bias towards genericity reusing BumpAllocator from pw_allocator, as well as internally using a "FramedAllocation" templated helper that might have been refactored out to be shared with other allocation code. The overhead of all of that resulted in a code size increase of about 300 bytes, as shown at https://pigweed.dev/pw_async2/code_size.html. See the row labeled: "Size of pw_async2’s C++ coroutine adapters". That extra cost was noticed. This change drastically reduces it: - Remove the use of BumpAllocator, replacing it with simpler local pointer adjustments. This saved 272 bytes, as BumpAllocator uses a non-inlineable virtual interface, along with other overhead. - Remove the templated "FramedAllocation" helper class. Despite it being instantiated for only one type, with inlining possible, eliminating it in favor of simpler pointer management saved another 64 bytes. - Remove the call to resize the allocation based on the space actually used. This saves another 16 bytes, and its likely there wouldn't be much space returned to the allocator anyway. - Store the pointer to the outer allocation, rather than an offset. This saves an additional 16 bytes by eliminating the need for some pointer arithmetic. - Removing the added PW_CHECK/PW_DCHECK calls. The original implementation didn't have similar checks. This saved another 80 bytes according to the size report. Here are the results from the pw_async2/code_size report: - Before the LLVM bugfix: +1,520 - After the LLVM bugfix: +1,808 - After these optimizations: +1,360 In other words, a net savings of 160 bytes over the pre-bugfix code. Test: bazelisk test //pw_async2/... Test: Examine pw_async2/code_size.html Change-Id: Id5ec409e731cbc9b7fd45e749831fda0ca4e0fd0 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/433693
Pigweed is an open source collection of embedded-targeted libraries–or as we like to call them, modules. These modules are building blocks and infrastructure that enable faster and more reliable development on small-footprint MMU-less 32-bit microcontrollers like the STMicroelectronics STM32L452 or the Nordic nRF52832.
For more information please see our website: https://pigweed.dev/.