From 1dd3b807ba040aabd5baba5a393f62870b737c81 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Thu, 22 May 2025 00:29:50 -0500 Subject: [PATCH] Dropped second resume-crystallization check With the new crystallization logic, we have two routes for resuming crystallization: 1. before finding our crystal heuristic, if buffer is in-block and enough for prog alignment 2. after finding our crystal heuristic, if crystal heuristic is in-block and enough for prog alignment But thinking about the second case, when would this happen that isn't caught by the first case? When there are fragments trailing our buffer? Are you writing to the file backwards? This corner case doesn't seem worth the extra logic. Benchmarking didn't find a noticeable difference in performance, so removing. Saves a bit of code: code stack ctx before: 37080 2304 636 after: 37056 (-0.1%) 2304 (+0.0%) 636 (+0.0%) --- lfs.c | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/lfs.c b/lfs.c index 8a5e42a9..386d3168 100644 --- a/lfs.c +++ b/lfs.c @@ -12537,43 +12537,8 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file, goto fragment; } - // exceeded crystallization threshold? - - // TODO does this make sense? wouldn't most useful append-crystals - // be caught with the above check? benchmark? - // - // can we resume crystallizing with the fragments on disk? - block_start = file->leaf.pos - - lfsr_bptr_off(&file->leaf.bptr); - block_end = file->leaf.pos - + lfsr_bptr_size(&file->leaf.bptr); - if (lfsr_bptr_isbptr(&file->leaf.bptr) - && lfsr_bptr_iserased(&file->leaf.bptr) - && crystal_start >= block_end - && crystal_start < block_start + lfs->cfg->block_size) { - int err = lfsr_file_crystallize(lfs, file, - file->leaf.pos - lfsr_bptr_off(&file->leaf.bptr), - crystal_end - - (file->leaf.pos - lfsr_bptr_off(&file->leaf.bptr)), - pos, buffer, size); - if (err) { - return err; - } - - // update buffer state, this may or may not make progress - lfs_soff_t d = lfs_max( - file->leaf.pos + lfsr_bptr_size(&file->leaf.bptr), - pos) - pos; - pos += d; - buffer += lfs_min(d, size); - size -= lfs_min(d, size); - - // we should be aligned now - aligned = true; - continue; - } - - // no? we need to allocate a new block + // exceeded crystallization threshold? we need to allocate a + // new block // if we're mid-crystallization, finish crystallizing the block // and graft it into our bshrub/btree