rdonly: Dropped file.b.shrub_ when LFS3_RDONLY

We don't need the staging shrub if we never stage shrubs!

The only hangup was reuse of the staging shrub to load bshrubs/btrees in
lfs3_file_fetch (we need to be able to fallback to the previous shrub if
we error in lfs3_file_resync), but this can be handled with a stack
allocated shrub.

If btree-leaf-caches make a return, we would need to stack allocate this
anyways due to the lopsided cost of the main/staging btrees/bshrubs
introduced to avoid wasting space on the useless
staging-shrub-leaf-cache.

This saves some code in LFS3_RDONLY, and apparently an instruction or
two in the default build (I guess stack loads/stores are cheaper?):

                   code          stack          ctx
  rdonly before:  10680            840          524
  rdonly after:   10640 (-0.4%)    816 (+0.0%)  524 (+0.0%)

  default before: 37324           2280          636
  default after:  37320 (-0.0%)   2280 (+0.0%)  636 (+0.0%)

It's not apparent in ctx because lfs3_info.name dominates (guh), but
this does save some RAM in lfs3_file_t:

  rdonly              ctx
  lfs3_file_t before: 136
  lfs3_file_t after:  112 (-17.6%)

It does add some stack cost to lfs3_file_fetch, but because this isn't
on the stack hot-path in either build, we don't really care:

  default                 code          stack          ctx
  lfs3_file_fetch before:  372            416            0
  lfs3_file_fetch after:   368 (-1.1%)    440 (+5.8%)    0 (+0.0%)
This commit is contained in:
Christopher Haster
2025-06-05 18:02:57 -05:00
parent 9eaab640e6
commit 7cc87a4fe6
2 changed files with 7 additions and 6 deletions
+2 -1
View File
@@ -720,8 +720,9 @@ typedef struct lfs3_bshrub {
// sign(trunk)=1 => bshrub
// sign(trunk)=0 => btree
lfs3_shrub_t shrub;
// TODO can we actually get rid of shrub_ when LFS3_RDONLY?
#ifndef LFS3_RDONLY
lfs3_shrub_t shrub_;
#endif
} lfs3_bshrub_t;
// littlefs file type