gc: Moved incremental gc behind ifdef LFS_GC

Incremental gc, being stateful and not gc-able (ironic), was always
going to need to be conditionally compilable.

This moves incremental gc behind the LFS_GC define, so that we can focus
on the "default" costs. This cuts lfs_t in nearly half!

  lfs_t with LFS_GC:   308
  lfs_t without LFS_C: 168 (-45.5%)

This does save less code than one might expect though. We still need
most of the internal traversal/gc logic for things like block allocation
and orphan cleanup, so most of the savings is limited to the RAM storing
the incremental state:

                          code          stack          ctx
  before:                37916           2608          768
  after with LFS_CFG:    37944 (+0.1%)   2608 (+0.0%)  768 (+0.0%)
  after without LFS_CFG: 37796 (-0.3%)   2608 (+0.0%)  620 (-19.3%)

On the flip side, this does mean most of the incremental gc
functionality is still availables in the lfsr_traversal_t APIs.

Applications with more advanced gc use-cases may actually benefit from
_not_ enabling the incremental gc APIs, and instead use the
lfsr_traversal_t APIs directly.
This commit is contained in:
Christopher Haster
2025-01-06 20:34:40 -06:00
parent 5d756fe698
commit 1b3054db89
8 changed files with 220 additions and 125 deletions
+16 -2
View File
@@ -24,7 +24,10 @@ defines.SIZE = [
'2*BLOCK_SIZE',
'8*BLOCK_SIZE',
]
if = '(SIZE*N)/BLOCK_SIZE <= 32'
if = [
'(SIZE*N)/BLOCK_SIZE <= 32',
'LFS_IFDEF_GC(true, METHOD != 1)',
]
code = '''
lfs_block_t i = 0;
while (true) {
@@ -98,7 +101,11 @@ code = '''
// find clobbered blocks with lfsr_gc
} else if (METHOD == 1) {
#ifdef LFS_GC
lfsr_gc(&lfs) => LFS_ERR_CORRUPT;
#else
LFS_UNREACHABLE();
#endif
// find clobbered blocks with lfsr_traversal_read
} else if (METHOD == 2) {
@@ -154,7 +161,10 @@ defines.SIZE = [
'2*BLOCK_SIZE',
'8*BLOCK_SIZE',
]
if = '(SIZE*N)/BLOCK_SIZE <= 32'
if = [
'(SIZE*N)/BLOCK_SIZE <= 32',
'LFS_IFDEF_GC(true, METHOD != 1)',
]
code = '''
lfs_block_t i = 0;
while (true) {
@@ -229,7 +239,11 @@ code = '''
// find clobbered blocks with lfsr_gc
} else if (METHOD == 1) {
#ifdef LFS_GC
lfsr_gc(&lfs) => LFS_ERR_CORRUPT;
#else
LFS_UNREACHABLE();
#endif
// find clobbered blocks with lfsr_traversal_read
} else if (METHOD == 2) {