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
4 files changed
tree: 055d2fbbd8720f06f3f57249643c4edb17222176
  1. .agents/
  2. .allstar/
  3. .gemini/
  4. .github/
  5. .vscode/
  6. build_overrides/
  7. docker/
  8. docs/
  9. kudzu/
  10. pw_alignment/
  11. pw_allocator/
  12. pw_allocator_zephyr/
  13. pw_analog/
  14. pw_android_toolchain/
  15. pw_arduino_build/
  16. pw_assert/
  17. pw_assert_basic/
  18. pw_assert_fuchsia/
  19. pw_assert_log/
  20. pw_assert_tokenized/
  21. pw_assert_trap/
  22. pw_assert_zephyr/
  23. pw_async/
  24. pw_async2/
  25. pw_async_basic/
  26. pw_async_fuchsia/
  27. pw_atomic/
  28. pw_base64/
  29. pw_bloat/
  30. pw_blob_store/
  31. pw_bluetooth/
  32. pw_bluetooth_hci/
  33. pw_bluetooth_profiles/
  34. pw_bluetooth_proxy/
  35. pw_bluetooth_sapphire/
  36. pw_boot/
  37. pw_boot_cortex_m/
  38. pw_build/
  39. pw_build_android/
  40. pw_build_info/
  41. pw_build_mcuxpresso/
  42. pw_bytes/
  43. pw_change/
  44. pw_channel/
  45. pw_checksum/
  46. pw_chre/
  47. pw_chrono/
  48. pw_chrono_embos/
  49. pw_chrono_freertos/
  50. pw_chrono_rp2040/
  51. pw_chrono_stl/
  52. pw_chrono_threadx/
  53. pw_chrono_zephyr/
  54. pw_cli/
  55. pw_cli_analytics/
  56. pw_clock_tree/
  57. pw_clock_tree_mcuxpresso/
  58. pw_compilation_testing/
  59. pw_config_loader/
  60. pw_console/
  61. pw_containers/
  62. pw_cpu_exception/
  63. pw_cpu_exception_cortex_m/
  64. pw_cpu_exception_risc_v/
  65. pw_crypto/
  66. pw_digital_io/
  67. pw_digital_io_linux/
  68. pw_digital_io_mcuxpresso/
  69. pw_digital_io_rp2040/
  70. pw_digital_io_zephyr/
  71. pw_display/
  72. pw_dma_mcuxpresso/
  73. pw_docgen/
  74. pw_doctor/
  75. pw_elf/
  76. pw_emu/
  77. pw_enum/
  78. pw_env_setup/
  79. pw_env_setup_zephyr/
  80. pw_file/
  81. pw_flatbuffers/
  82. pw_format/
  83. pw_fortifier/
  84. pw_function/
  85. pw_fuzzer/
  86. pw_grpc/
  87. pw_hdlc/
  88. pw_hex_dump/
  89. pw_i2c/
  90. pw_i2c_linux/
  91. pw_i2c_mcuxpresso/
  92. pw_i2c_rp2040/
  93. pw_i2c_zephyr/
  94. pw_ide/
  95. pw_interrupt/
  96. pw_interrupt_cortex_m/
  97. pw_interrupt_freertos/
  98. pw_interrupt_zephyr/
  99. pw_intrusive_ptr/
  100. pw_json/
  101. pw_kernel/
  102. pw_kvs/
  103. pw_libc/
  104. pw_libcxx/
  105. pw_log/
  106. pw_log_android/
  107. pw_log_basic/
  108. pw_log_fuchsia/
  109. pw_log_null/
  110. pw_log_rpc/
  111. pw_log_string/
  112. pw_log_tokenized/
  113. pw_log_zephyr/
  114. pw_malloc/
  115. pw_malloc_freelist/
  116. pw_malloc_freertos/
  117. pw_memory/
  118. pw_metric/
  119. pw_module/
  120. pw_multibuf/
  121. pw_multisink/
  122. pw_numeric/
  123. pw_package/
  124. pw_perf_test/
  125. pw_persistent_ram/
  126. pw_polyfill/
  127. pw_preprocessor/
  128. pw_presubmit/
  129. pw_protobuf/
  130. pw_protobuf_compiler/
  131. pw_random/
  132. pw_random_fuchsia/
  133. pw_result/
  134. pw_ring_buffer/
  135. pw_router/
  136. pw_rpc/
  137. pw_rpc_transport/
  138. pw_rust/
  139. pw_sensor/
  140. pw_snapshot/
  141. pw_software_update/
  142. pw_span/
  143. pw_spi/
  144. pw_spi_linux/
  145. pw_spi_mcuxpresso/
  146. pw_spi_rp2040/
  147. pw_spi_zephyr/
  148. pw_status/
  149. pw_stm32cube_build/
  150. pw_stream/
  151. pw_stream_uart_linux/
  152. pw_stream_uart_mcuxpresso/
  153. pw_string/
  154. pw_symbolizer/
  155. pw_sync/
  156. pw_sync_baremetal/
  157. pw_sync_embos/
  158. pw_sync_freertos/
  159. pw_sync_stl/
  160. pw_sync_threadx/
  161. pw_sync_zephyr/
  162. pw_sys_io/
  163. pw_sys_io_ambiq_sdk/
  164. pw_sys_io_arduino/
  165. pw_sys_io_baremetal_lm3s6965evb/
  166. pw_sys_io_baremetal_stm32f429/
  167. pw_sys_io_emcraft_sf2/
  168. pw_sys_io_mcuxpresso/
  169. pw_sys_io_rp2040/
  170. pw_sys_io_stdio/
  171. pw_sys_io_stm32cube/
  172. pw_sys_io_zephyr/
  173. pw_system/
  174. pw_target_runner/
  175. pw_thread/
  176. pw_thread_embos/
  177. pw_thread_freertos/
  178. pw_thread_stl/
  179. pw_thread_threadx/
  180. pw_thread_zephyr/
  181. pw_time/
  182. pw_tls_client/
  183. pw_tls_client_boringssl/
  184. pw_tls_client_mbedtls/
  185. pw_tokenizer/
  186. pw_toolchain/
  187. pw_trace/
  188. pw_trace_tokenized/
  189. pw_transfer/
  190. pw_uart/
  191. pw_uart_mcuxpresso/
  192. pw_unit_test/
  193. pw_uuid/
  194. pw_varint/
  195. pw_watch/
  196. pw_web/
  197. pw_work_queue/
  198. seed/
  199. targets/
  200. third_party/
  201. zephyr/
  202. .bazelignore
  203. .bazelrc
  204. .bazelversion
  205. .black.toml
  206. .clang-format
  207. .clang-tidy
  208. .git-blame-ignore-revs
  209. .gitattributes
  210. .gitignore
  211. .gn
  212. .mypy.ini
  213. .prettierignore
  214. .prettierrc.cjs
  215. .pw_ide.yaml
  216. .pylintrc
  217. .ruff.toml
  218. activate.bat
  219. Android.bp
  220. AUTHORS
  221. bootstrap.bat
  222. bootstrap.fish
  223. bootstrap.sh
  224. BUILD.bazel
  225. BUILD.gn
  226. BUILDCONFIG.gn
  227. CMakeLists.txt
  228. EXTENDED_OWNERS
  229. GEMINI.md
  230. go.mod
  231. go.sum
  232. Kconfig.zephyr
  233. LICENSE
  234. MODULE.bazel
  235. MODULE.bazel.lock
  236. modules.gni
  237. OWNERS
  238. package.json
  239. pigweed.json
  240. PIGWEED_MODULES
  241. pw
  242. README.md
  243. REPO.bazel
  244. rustfmt.toml
  245. tsconfig.json
  246. workflows.json
  247. WORKSPACE_OWNERS
README.md

Pigweed

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/.

Links