Skip to content

Commit 3f2e8b5

Browse files
committed
Manually inlined lfs3_file_crystallize into lfs3_file_flush_
This was the main culprit behind our stack increase. Inlining lfs3_file_crystallize into lfs3_file_flush_ adds a bit of code, but as a tradeoff: - Keeps all lfs3_file_crystallization_ calls at the same abstraction level, which is generally easier to reason about and avoids issues with things like lfs3_alloc_ckpoints. - Makes some low-level interactions, such as LFS3_o_UNCRYST masking, more obvious. - Reduces the stack hot-path by the cost of lfs3_file_flush_ Saves some stack at a code cost: code stack ctx before: 37492 2464 656 after: 37504 (+0.0%) 2448 (-0.6%) 656 (+0.0%) Now that the dust has settled a bit, we can also compare the lazy grafting vs lazy crystallization builds: code stack ctx lazy-graft: 38020 2456 656 lazycryst: 37504 (-1.4%) 2448 (-0.3%) 656 (+0.0%)
1 parent 35e4073 commit 3f2e8b5

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lfs3.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13095,9 +13095,17 @@ static int lfs3_file_flush_(lfs3_t *lfs3, lfs3_file_t *file,
1309513095

1309613096
// if we're mid-crystallization, finish crystallizing the block
1309713097
// and graft it into our bshrub/btree
13098-
int err = lfs3_file_crystallize(lfs3, file);
13099-
if (err) {
13100-
return err;
13098+
if (lfs3_o_isuncryst(file->b.o.flags)) {
13099+
// finish crystallizing
13100+
int err = lfs3_file_crystallize_(lfs3, file,
13101+
file->leaf.pos - lfs3_bptr_off(&file->leaf.bptr), -1, -1,
13102+
0, NULL, 0);
13103+
if (err) {
13104+
return err;
13105+
}
13106+
13107+
// we should have crystallized
13108+
LFS3_ASSERT(!lfs3_o_isuncryst(file->b.o.flags));
1310113109
}
1310213110

1310313111
// before we can crystallize we need to figure out the best
@@ -13138,7 +13146,7 @@ static int lfs3_file_flush_(lfs3_t *lfs3, lfs3_file_t *file,
1313813146
// start crystallizing!
1313913147
//
1314013148
// lfs3_file_crystallize_ handles block allocation/relocation
13141-
err = lfs3_file_crystallize_(lfs3, file,
13149+
int err = lfs3_file_crystallize_(lfs3, file,
1314213150
crystal_start, -1, crystal_end - crystal_start,
1314313151
pos, buffer, size);
1314413152
if (err) {
@@ -13451,6 +13459,8 @@ int lfs3_file_flush(lfs3_t *lfs3, lfs3_file_t *file) {
1345113459
}
1345213460
// unflushed files must be unsynced
1345313461
LFS3_ASSERT(lfs3_o_isunsync(file->b.o.flags));
13462+
// uncrystallized files must be unsynced
13463+
LFS3_ASSERT(lfs3_o_isunsync(file->b.o.flags));
1345413464
// unflushed files can't be readonly
1345513465
LFS3_ASSERT(!lfs3_o_isrdonly(file->b.o.flags));
1345613466

@@ -13479,8 +13489,8 @@ int lfs3_file_flush(lfs3_t *lfs3, lfs3_file_t *file) {
1347913489
file->b.o.flags &= ~LFS3_o_UNFLUSH;
1348013490
}
1348113491

13482-
// and crystallize/graft our leaf
1348313492
#if !defined(LFS3_KVONLY) && !defined(LFS3_2BONLY)
13493+
// and crystallize/graft our leaf
1348413494
err = lfs3_file_crystallize(lfs3, file);
1348513495
if (err) {
1348613496
goto failed;

0 commit comments

Comments
 (0)