Skip to content

Move persistence from out of band to in-band#399

Open
ivmarkov wants to merge 3 commits intoproject-chip:mainfrom
sysgrok:inband-persistence
Open

Move persistence from out of band to in-band#399
ivmarkov wants to merge 3 commits intoproject-chip:mainfrom
sysgrok:inband-persistence

Conversation

@ivmarkov
Copy link
Copy Markdown
Contributor

@ivmarkov ivmarkov commented Mar 31, 2026

Background

Currently, the persistence metaphor of rs-matter is that rs-matter cannot really persist itself.
Instead, it can tell interested parties whether it was changed (is dirty).

This "dirty" tracking mechanism allows for the implementation of custom persistence by just having the persister listening on the "dirty" status of rs-matter and then persisting the fabrics, basic info settings and networks when they get changed / "dirty".

An interesting property of such an implementation is that - by necessity - it is out of band persistence.
What that means is that when - say - a new fabric had been commissioned into the device, that fabric might had not yet been saved to the persistent storage of the device at the time when the device communicates to the commissioner a success. At that time, the fabrics become "changed" / "dirty", but only later the async persister might trigger and flush the fabric to the persistent storage.

This type of implementation of persistence was a necessity back in the early days of rs-matter, when Rust did not support (yet) async traits. And we DO want the persister to be an async trait, because on embedded baremetal, all interesting persisters are async (sequential-map, ekv), even if the access to the NOR FLASH is not necessarily async.

What this PR does

As the name suggests, the PR switches the persistence of rs-matter to a regular in-band one, where rs-matter takes an async persistence trait impl - KvBlobStore - and then calls the persistence trait as-necessary from the NOC, Wifi, Thread, Basic Info, Gen Comm and other clusters that change any of the rs-matter values which are subject to persistence (fabrics, basic info settings and wireless networks).

But why?

First of all, I'm not necessarily convinced that this in-band persistence is an obvious huge win over the existing out-of-band one. For one, it converts even more system cluster handlers from non-async to async:

  • Basic Info
  • NOC
  • Wifi
  • Thread
  • General commissioning
  • Groups
  • Group Key Mgmt

... basically all clusters that modify non-volatile data now need to be async, so that they can call the persister on successful modification.

... and as we know from #366 , async cluster handlers do not have 0% overhead.

On the other hand, an in-band persistence has the following benefits:

  • What users typically assume/expect
  • Perhaps more comformant to the Matter Core spec, in that with in-band - indeed - e.g. the fabric IS persisted before the device sends to the commissioner a "Success" reply
  • We use/convert the out-of-band persistence of rs-matter to a KvBlobStore trait in downstream rs-matter-stack/embassy/esp-idf anyway. So why not push the KvBlobStore upstream to rs-matter?
  • It is very easy to persist the removal of a fabric. You just do it, right after the fabric was removed from the transient storage. With a "dirty" metaphor, that's a bit challenging as you need to keep a list of removed fabrics then (complex), or worse - keep a generic "something changed" flag and then - in the persister that kicks-in later - re-persist ALL fabrics. which is the culprit of Do not persist all fabrics as a single TLV sysgrok/rs-matter-stack#27

Last but not least, switching to in-band storage makes fixing sysgrok/rs-matter-stack#27 very easy, as this PR does.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the persistence layer in rs-matter by introducing a new KvBlobStore trait and a transactional PersistTransaction utility to handle state persistence more robustly. It replaces the previous file-based PSM with a more granular key-value store approach, updates various cluster handlers to use this new persistence mechanism, and migrates several synchronous cluster handlers to asynchronous ones. My feedback highlights the importance of ensuring consistent transaction scoping and error handling during the commit phase of these new persistence operations to maintain data integrity.

@ivmarkov ivmarkov force-pushed the inband-persistence branch 3 times, most recently from 8ec0b49 to 721c35e Compare March 31, 2026 14:09
@github-actions
Copy link
Copy Markdown

PR #399: Size comparison from 8f3d2cc to 721c35e

Increases above 0.2%:

platform target config section 8f3d2cc 721c35e change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396818 428336 31518 7.9
RAM 68240 68696 456 0.7
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334344 366872 32528 9.7
RAM 64488 64936 448 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306080 332704 26624 8.7
RAM 63984 64432 448 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 901991 58104 6.9
RAM 66984 67848 864 1.3
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1969056 2038808 69752 3.5
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896848 1968352 71504 3.8
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3210568 3283152 72584 2.3
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850256 47672 5.9
RAM 2832 2856 24 0.8
Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section 8f3d2cc 721c35e change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396818 428336 31518 7.9
RAM 68240 68696 456 0.7
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334344 366872 32528 9.7
RAM 64488 64936 448 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306080 332704 26624 8.7
RAM 63984 64432 448 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 901991 58104 6.9
RAM 66984 67848 864 1.3
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1969056 2038808 69752 3.5
RAM 52424 52384 -40 -0.1
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896848 1968352 71504 3.8
RAM 52096 52056 -40 -0.1
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3210568 3283152 72584 2.3
RAM 5784 5784 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850256 47672 5.9
RAM 2832 2856 24 0.8

@ivmarkov ivmarkov force-pushed the inband-persistence branch 2 times, most recently from 1d909a0 to 3fe7d1f Compare March 31, 2026 14:57
@github-actions
Copy link
Copy Markdown

PR #399: Size comparison from 8f3d2cc to 3fe7d1f

Increases above 0.2%:

platform target config section 8f3d2cc 3fe7d1f change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396818 428336 31518 7.9
RAM 68240 68696 456 0.7
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334344 366872 32528 9.7
RAM 64488 64936 448 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306080 332704 26624 8.7
RAM 63984 64432 448 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 901991 58104 6.9
RAM 66984 67848 864 1.3
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1969056 2038560 69504 3.5
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896848 1968360 71512 3.8
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3210568 3283152 72584 2.3
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850280 47696 5.9
RAM 2832 2856 24 0.8
Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section 8f3d2cc 3fe7d1f change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396818 428336 31518 7.9
RAM 68240 68696 456 0.7
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334344 366872 32528 9.7
RAM 64488 64936 448 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306080 332704 26624 8.7
RAM 63984 64432 448 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 901991 58104 6.9
RAM 66984 67848 864 1.3
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1969056 2038560 69504 3.5
RAM 52424 52384 -40 -0.1
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896848 1968360 71512 3.8
RAM 52096 52056 -40 -0.1
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3210568 3283152 72584 2.3
RAM 5784 5784 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850280 47696 5.9
RAM 2832 2856 24 0.8

@ivmarkov ivmarkov force-pushed the inband-persistence branch from 3fe7d1f to 06cdc7e Compare March 31, 2026 16:05
@github-actions
Copy link
Copy Markdown

PR #399: Size comparison from 8f3d2cc to 06cdc7e

Increases above 0.2%:

platform target config section 8f3d2cc 06cdc7e change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396818 428336 31518 7.9
RAM 68240 68696 456 0.7
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334344 366872 32528 9.7
RAM 64488 64936 448 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306080 332704 26624 8.7
RAM 63984 64432 448 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 901991 58104 6.9
RAM 66984 67848 864 1.3
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1969056 2037952 68896 3.5
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896848 1967560 70712 3.7
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3210568 3281968 71400 2.2
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850032 47448 5.9
RAM 2832 2856 24 0.8
Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section 8f3d2cc 06cdc7e change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396818 428336 31518 7.9
RAM 68240 68696 456 0.7
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334344 366872 32528 9.7
RAM 64488 64936 448 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306080 332704 26624 8.7
RAM 63984 64432 448 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 901991 58104 6.9
RAM 66984 67848 864 1.3
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1969056 2037952 68896 3.5
RAM 52424 52384 -40 -0.1
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896848 1967560 70712 3.7
RAM 52096 52056 -40 -0.1
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3210568 3281968 71400 2.2
RAM 5784 5784 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850032 47448 5.9
RAM 2832 2856 24 0.8

@ivmarkov
Copy link
Copy Markdown
Contributor Author

ivmarkov commented Mar 31, 2026

Given the flash code size increase, I'm thinking if we merge this, we should also merge #366

After all, one of the reasons #366 popped up in the first place, was precisely to allow in-band async persistence for all clusters, which means we should have only async clusters.

@ivmarkov ivmarkov force-pushed the inband-persistence branch from 06cdc7e to 6ef5b43 Compare March 31, 2026 16:52
@github-actions
Copy link
Copy Markdown

PR #399: Size comparison from 8f3d2cc to 6ef5b43

Increases above 0.2%:

platform target config section 8f3d2cc 6ef5b43 change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396818 428426 31608 8.0
RAM 68240 68696 456 0.7
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334344 366968 32624 9.8
RAM 64488 64936 448 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306080 332756 26676 8.7
RAM 63984 64432 448 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 902167 58280 6.9
RAM 66984 67848 864 1.3
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1969056 2038096 69040 3.5
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896848 1967704 70856 3.7
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3210568 3282144 71576 2.2
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850032 47448 5.9
RAM 2832 2856 24 0.8
Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section 8f3d2cc 6ef5b43 change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396818 428426 31608 8.0
RAM 68240 68696 456 0.7
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334344 366968 32624 9.8
RAM 64488 64936 448 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306080 332756 26676 8.7
RAM 63984 64432 448 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 902167 58280 6.9
RAM 66984 67848 864 1.3
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1969056 2038096 69040 3.5
RAM 52424 52384 -40 -0.1
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896848 1967704 70856 3.7
RAM 52096 52056 -40 -0.1
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3210568 3282144 71576 2.2
RAM 5784 5784 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850032 47448 5.9
RAM 2832 2856 24 0.8

@ivmarkov ivmarkov force-pushed the inband-persistence branch from 6ef5b43 to 159230f Compare April 1, 2026 09:54
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

PR #399: Size comparison from 8f3d2cc to 159230f

Increases above 0.2%:

platform target config section 8f3d2cc 159230f change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396818 428570 31752 8.0
RAM 68240 68680 440 0.6
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334344 367152 32808 9.8
RAM 64488 64920 432 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306080 332852 26772 8.7
RAM 63984 64416 432 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 902399 58512 6.9
RAM 66984 67816 832 1.2
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1969056 2038104 69048 3.5
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896848 1967560 70712 3.7
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3210568 3281112 70544 2.2
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850032 47448 5.9
RAM 2832 2856 24 0.8
Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section 8f3d2cc 159230f change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396818 428570 31752 8.0
RAM 68240 68680 440 0.6
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334344 367152 32808 9.8
RAM 64488 64920 432 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306080 332852 26772 8.7
RAM 63984 64416 432 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 902399 58512 6.9
RAM 66984 67816 832 1.2
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1969056 2038104 69048 3.5
RAM 52424 52352 -72 -0.1
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896848 1967560 70712 3.7
RAM 52096 52056 -40 -0.1
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3210568 3281112 70544 2.2
RAM 5784 5784 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850032 47448 5.9
RAM 2832 2856 24 0.8

@ivmarkov ivmarkov force-pushed the inband-persistence branch from 159230f to 94506e5 Compare April 1, 2026 10:32
@ivmarkov ivmarkov marked this pull request as ready for review April 1, 2026 10:32
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

PR #399: Size comparison from c4f1291 to 94506e5

Increases above 0.2%:

platform target config section c4f1291 94506e5 change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396816 428562 31746 8.0
RAM 68240 68680 440 0.6
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334376 367180 32804 9.8
RAM 64488 64928 440 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306088 332844 26756 8.7
RAM 63984 64424 440 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 902399 58512 6.9
RAM 66984 67816 832 1.2
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1968912 2038136 69224 3.5
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896704 1967560 70856 3.7
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3209480 3281112 71632 2.2
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850032 47448 5.9
RAM 2832 2856 24 0.8
Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section c4f1291 94506e5 change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396816 428562 31746 8.0
RAM 68240 68680 440 0.6
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334376 367180 32804 9.8
RAM 64488 64928 440 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306088 332844 26756 8.7
RAM 63984 64424 440 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 902399 58512 6.9
RAM 66984 67816 832 1.2
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1968912 2038136 69224 3.5
RAM 52424 52352 -72 -0.1
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896704 1967560 70856 3.7
RAM 52096 52056 -40 -0.1
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3209480 3281112 71632 2.2
RAM 5784 5784 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850032 47448 5.9
RAM 2832 2856 24 0.8

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

PR #399: Size comparison from c4f1291 to 1952d23

Increases above 0.2%:

platform target config section c4f1291 1952d23 change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396816 427846 31030 7.8
RAM 68240 68680 440 0.6
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334376 365092 30716 9.2
RAM 64488 64920 432 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306088 331524 25436 8.3
RAM 63984 64416 432 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 902639 58752 7.0
RAM 66984 67816 832 1.2
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1968912 2038632 69720 3.5
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896704 1968480 71776 3.8
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3209480 3302240 92760 2.9
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850064 47480 5.9
RAM 2832 2856 24 0.8
Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section c4f1291 1952d23 change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396816 427846 31030 7.8
RAM 68240 68680 440 0.6
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334376 365092 30716 9.2
RAM 64488 64920 432 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306088 331524 25436 8.3
RAM 63984 64416 432 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 902639 58752 7.0
RAM 66984 67816 832 1.2
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1968912 2038632 69720 3.5
RAM 52424 52352 -72 -0.1
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896704 1968480 71776 3.8
RAM 52096 52056 -40 -0.1
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3209480 3302240 92760 2.9
RAM 5784 5784 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850064 47480 5.9
RAM 2832 2856 24 0.8

@ivmarkov ivmarkov force-pushed the inband-persistence branch from 1952d23 to e015ede Compare April 1, 2026 12:41
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

PR #399: Size comparison from c4f1291 to e015ede

Increases above 0.2%:

platform target config section c4f1291 e015ede change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396816 427846 31030 7.8
RAM 68240 68680 440 0.6
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334376 365092 30716 9.2
RAM 64488 64920 432 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306088 331524 25436 8.3
RAM 63984 64416 432 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 902639 58752 7.0
RAM 66984 67816 832 1.2
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1968912 2038632 69720 3.5
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896704 1968480 71776 3.8
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3209480 3302240 92760 2.9
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850064 47480 5.9
RAM 2832 2856 24 0.8
Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section c4f1291 e015ede change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396816 427846 31030 7.8
RAM 68240 68680 440 0.6
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334376 365092 30716 9.2
RAM 64488 64920 432 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306088 331524 25436 8.3
RAM 63984 64416 432 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 902639 58752 7.0
RAM 66984 67816 832 1.2
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1968912 2038632 69720 3.5
RAM 52424 52352 -72 -0.1
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896704 1968480 71776 3.8
RAM 52096 52056 -40 -0.1
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3209480 3302240 92760 2.9
RAM 5784 5784 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850064 47480 5.9
RAM 2832 2856 24 0.8

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

PR #399: Size comparison from c4f1291 to e457ffa

Increases above 0.2%:

platform target config section c4f1291 e457ffa change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396816 427328 30512 7.7
RAM 68240 68664 424 0.6
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334376 362028 27652 8.3
RAM 64488 64904 416 0.6
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306088 330172 24084 7.9
RAM 63984 64400 416 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 895863 51976 6.2
RAM 66984 67792 808 1.2
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1968912 2031776 62864 3.2
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896704 1961528 64824 3.4
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3209480 3312656 103176 3.2
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850064 47480 5.9
RAM 2832 2856 24 0.8
Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section c4f1291 e457ffa change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396816 427328 30512 7.7
RAM 68240 68664 424 0.6
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334376 362028 27652 8.3
RAM 64488 64904 416 0.6
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306088 330172 24084 7.9
RAM 63984 64400 416 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 895863 51976 6.2
RAM 66984 67792 808 1.2
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1968912 2031776 62864 3.2
RAM 52424 52352 -72 -0.1
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896704 1961528 64824 3.4
RAM 52096 52056 -40 -0.1
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3209480 3312656 103176 3.2
RAM 5784 5784 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850064 47480 5.9
RAM 2832 2856 24 0.8

@ivmarkov ivmarkov force-pushed the inband-persistence branch 2 times, most recently from 44b31a9 to 3cb42dd Compare April 1, 2026 14:37
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

PR #399: Size comparison from c4f1291 to 3cb42dd

Increases above 0.2%:

platform target config section c4f1291 3cb42dd change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396816 425484 28668 7.2
RAM 68240 68664 424 0.6
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334376 360736 26360 7.9
RAM 64488 64904 416 0.6
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306088 328836 22748 7.4
RAM 63984 64400 416 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 894023 50136 5.9
RAM 66984 67792 808 1.2
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1968912 2027000 58088 3.0
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896704 1958312 61608 3.2
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3209480 3305008 95528 3.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850064 47480 5.9
RAM 2832 2856 24 0.8
Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section c4f1291 3cb42dd change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396816 425484 28668 7.2
RAM 68240 68664 424 0.6
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334376 360736 26360 7.9
RAM 64488 64904 416 0.6
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306088 328836 22748 7.4
RAM 63984 64400 416 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 894023 50136 5.9
RAM 66984 67792 808 1.2
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1968912 2027000 58088 3.0
RAM 52424 52352 -72 -0.1
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896704 1958312 61608 3.2
RAM 52096 52056 -40 -0.1
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3209480 3305008 95528 3.0
RAM 5784 5784 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850064 47480 5.9
RAM 2832 2856 24 0.8

@ivmarkov
Copy link
Copy Markdown
Contributor Author

ivmarkov commented Apr 1, 2026

This PR now did cherry-pick the optimizations from #366 which are basically "use the -> impl Future syntax for one-line delegate methods in the code generated by the import! macro".

This did result in a small size decrease: #399 (comment) (i.e. from 9.8% increase down to 9.2% for the most badly affected thumbv6m-none-eabi target)

The PR also introduced and uses a new trick - delayed_ready which allows to use the -> impl Future trick for async fns which do not have a single await point inside. This did result in a slightly more meaningful additional decrease from 9.2% down to 7.9% for the same target.

Still, all these reduced the introduced code bloat by only 20% compared to a straightforward usage of the async syntax.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

PR #399: Size comparison from c4f1291 to 93ebab5

Increases above 0.2%:

platform target config section c4f1291 93ebab5 change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396816 425490 28674 7.2
RAM 68240 68664 424 0.6
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334376 360720 26344 7.9
RAM 64488 64912 424 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306088 328840 22752 7.4
RAM 63984 64400 416 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 894007 50120 5.9
RAM 66984 67792 808 1.2
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1968912 2026968 58056 2.9
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896704 1958296 61592 3.2
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3209480 3305056 95576 3.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850064 47480 5.9
RAM 2832 2856 24 0.8
Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section c4f1291 93ebab5 change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396816 425490 28674 7.2
RAM 68240 68664 424 0.6
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334376 360720 26344 7.9
RAM 64488 64912 424 0.7
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306088 328840 22752 7.4
RAM 63984 64400 416 0.7
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 894007 50120 5.9
RAM 66984 67792 808 1.2
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1968912 2026968 58056 2.9
RAM 52424 52352 -72 -0.1
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896704 1958296 61592 3.2
RAM 52096 52056 -40 -0.1
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3209480 3305056 95576 3.0
RAM 5784 5784 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850064 47480 5.9
RAM 2832 2856 24 0.8

@ivmarkov ivmarkov force-pushed the inband-persistence branch from 309bdbc to 4c182df Compare April 2, 2026 11:44
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

PR #399: Size comparison from c4f1291 to 4c182df

Increases above 0.2%:

platform target config section c4f1291 4c182df change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396816 425576 28760 7.2
RAM 68240 68728 488 0.7
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334376 360724 26348 7.9
RAM 64488 64976 488 0.8
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306088 328900 22812 7.5
RAM 63984 64464 480 0.8
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 894119 50232 6.0
RAM 66984 67920 936 1.4
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1968912 2027144 58232 3.0
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896704 1958392 61688 3.3
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3209480 3306352 96872 3.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850064 47480 5.9
RAM 2832 2856 24 0.8
Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section c4f1291 4c182df change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 396816 425576 28760 7.2
RAM 68240 68728 488 0.7
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 334376 360724 26348 7.9
RAM 64488 64976 488 0.8
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 306088 328900 22812 7.5
RAM 63984 64464 480 0.8
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 843887 894119 50232 6.0
RAM 66984 67920 936 1.4
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1968912 2027144 58232 3.0
RAM 52424 52352 -72 -0.1
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1896704 1958392 61688 3.3
RAM 52096 52056 -40 -0.1
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3209480 3306352 96872 3.0
RAM 5784 5784 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850064 47480 5.9
RAM 2832 2856 24 0.8

Experiment with delayed_ready and impl Future syntax in an effort to reduce the code bloat

Expose the wireless networks

Make it easier to integrate sequential_map downstream
@ivmarkov ivmarkov force-pushed the inband-persistence branch from 4c182df to b2427f6 Compare April 2, 2026 21:00
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

PR #399: Size comparison from d5ad8ed to b2427f6

Increases above 0.2%:

platform target config section d5ad8ed b2427f6 change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 395380 426984 31604 8.0
RAM 68064 68632 568 0.8
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 333348 363124 29776 8.9
RAM 64312 64880 568 0.9
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 305776 330896 25120 8.2
RAM 63808 64368 560 0.9
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 832223 893479 61256 7.4
RAM 66632 67728 1096 1.6
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1963912 2023064 59152 3.0
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1895504 1954840 59336 3.1
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3220752 3271680 50928 1.6
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850064 47480 5.9
RAM 2832 2856 24 0.8
Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section d5ad8ed b2427f6 change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 395380 426984 31604 8.0
RAM 68064 68632 568 0.8
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 333348 363124 29776 8.9
RAM 64312 64880 568 0.9
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 305776 330896 25120 8.2
RAM 63808 64368 560 0.9
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 832223 893479 61256 7.4
RAM 66632 67728 1096 1.6
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1963912 2023064 59152 3.0
RAM 52424 52352 -72 -0.1
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1895504 1954840 59336 3.1
RAM 52096 52056 -40 -0.1
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3220752 3271680 50928 1.6
RAM 5784 5784 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850064 47480 5.9
RAM 2832 2856 24 0.8

@ivmarkov
Copy link
Copy Markdown
Contributor Author

ivmarkov commented Apr 3, 2026

I've now built a stage2 rustc from this much anticipated PR (this hash) and compared cargo size of that compiler with a regular rustc nightly from 2026-03-25.

The TL;DR is: I don't see an enormous reduction in neither BSS nor FLASH size (I expected a bit the latter as well due to this comment):

  • Code-size reduction - max 2%
  • BSS reduction - max 3%

With that said, the code-patterns "-Z pack-coroutine-layout=captures-only" is supposed to optimize (i.e. single-line async delegates using the async syntax) are actually mostly eradicated from the rs-matter codebase; also, we avoid passing by value/move large types into the futures - it is all by reference instead; yet and as per below, I was hoping it would address the code-size problem as described in #366 as well.

Comparisons below; "inband-persistence" is basically this PR. "inband-persistence-sync" is a variation of this PR where the inband persistence API (KvBlobStore) is converted from async to non-async (hence the large reduction in code bloat).

Branch "inband-persistence"

Target cargo size --release --target thumbv6m-none-eabi

#135527 + export RUSTFLAGS="-Z pack-coroutine-layout=captures-only"
text data bss dec hex filename
348088 0 62656 410744 64478 bloat-check

nightly:
text data bss dec hex filename
355112 0 64696 419808 667e0 bloat-check

Target cargo size --release --target thumbv7em-none-eabi

#135527 + export RUSTFLAGS="-Z pack-coroutine-layout=captures-only"
text data bss dec hex filename
319648 24 62304 381976 5d418 bloat-check

nightly:
text data bss dec hex filename
321956 24 64344 386324 5e514 bloat-check

Branch "inband-persistence-sync"

Target cargo size --release --target thumbv7em-none-eabi

#135527 + export RUSTFLAGS="-Z pack-coroutine-layout=captures-only"
text data bss dec hex filename
302948 24 62112 365084 5921c bloat-check

nightly:
text data bss dec hex filename
304516 24 63800 368340 59ed4 bloat-check

Target cargo size --release --target thumbv6m-none-eabi

#135527 + export RUSTFLAGS="-Z pack-coroutine-layout=captures-only"
text data bss dec hex filename
326196 0 62464 388660 5ee34 bloat-check

nightly:
text data bss dec hex filename
329520 0 64152 393672 601c8 bloat-check

#135527 + unset RUSTFLAGS
text data bss dec hex filename
329316 0 64200 393516 6012c bloat-check

@ivmarkov
Copy link
Copy Markdown
Contributor Author

ivmarkov commented Apr 4, 2026

baa4728 reverts to a non-async API for KvBlobStore (yes, that would mean async-only blob stores will have to be wrapped in embassy_futures::block_on but then non-DMA KVs writing to MCU's NOR-FLASH are almost always blocking anyway?).

The non-async KvBlobStore allows us to revert to regular Handler impls for most of the system clusters which cuts down the code bloat.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 4, 2026

PR #399: Size comparison from d5ad8ed to baa4728

Increases above 0.2%:

platform target config section d5ad8ed baa4728 change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 395380 403416 8036 2.0
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 333348 337492 4144 1.2
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 305776 312332 6556 2.1
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 832223 837919 5696 0.7
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850016 47432 5.9
RAM 2832 2856 24 0.8
Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section d5ad8ed baa4728 change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 395380 403416 8036 2.0
RAM 68064 68072 8 0.0
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 333348 337492 4144 1.2
RAM 64312 64320 8 0.0
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 305776 312332 6556 2.1
RAM 63808 63800 -8 -0.0
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 832223 837919 5696 0.7
RAM 66632 66616 -16 -0.0
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1963912 1955568 -8344 -0.4
RAM 52424 52352 -72 -0.1
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1895504 1888800 -6704 -0.4
RAM 52096 52056 -40 -0.1
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3220752 3216288 -4464 -0.1
RAM 5784 5784 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850016 47432 5.9
RAM 2832 2856 24 0.8

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 4, 2026

PR #399: Size comparison from d5ad8ed to bcb4893

Increases above 0.2%:

platform target config section d5ad8ed bcb4893 change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 395380 403416 8036 2.0
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 333348 337492 4144 1.2
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 305776 312332 6556 2.1
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 832223 837919 5696 0.7
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850792 48208 6.0
RAM 2832 2856 24 0.8
Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section d5ad8ed bcb4893 change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 395380 403416 8036 2.0
RAM 68064 68072 8 0.0
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 333348 337492 4144 1.2
RAM 64312 64320 8 0.0
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 305776 312332 6556 2.1
RAM 63808 63800 -8 -0.0
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 832223 837919 5696 0.7
RAM 66632 66616 -16 -0.0
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1963912 1956096 -7816 -0.4
RAM 52424 52352 -72 -0.1
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1895504 1889456 -6048 -0.3
RAM 52096 52056 -40 -0.1
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3220752 3216992 -3760 -0.1
RAM 5784 5784 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 802584 850792 48208 6.0
RAM 2832 2856 24 0.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant