Skip to content

Commit 1fb6a19

Browse files
committed
Reduced ctz traverse runtime by 2x
Unfortunately for us, the ctz skip-list does not offer very much benefit for full traversals. Since the information about which blocks are in use are spread throughout the file, we can't use the fast-lanes embedded in the skip-list without missing blocks. However, it turns out we can at least use the 2nd level of the skip-list without missing any blocks. From an asymptotic analysis, a constant speed up isn't interesting, but from a pragmatic perspective, a 2x speedup is not bad.
1 parent db88727 commit 1fb6a19

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Diff for: lfs.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -1195,12 +1195,22 @@ static int lfs_ctz_traverse(lfs_t *lfs,
11951195
return 0;
11961196
}
11971197

1198-
err = lfs_cache_read(lfs, rcache, pcache, head, 0, &head, 4);
1198+
lfs_block_t heads[2];
1199+
int count = 2 - (index & 1);
1200+
err = lfs_cache_read(lfs, rcache, pcache, head, 0, &heads, count*4);
11991201
if (err) {
12001202
return err;
12011203
}
12021204

1203-
index -= 1;
1205+
for (int i = 0; i < count-1; i++) {
1206+
err = cb(data, heads[i]);
1207+
if (err) {
1208+
return err;
1209+
}
1210+
}
1211+
1212+
head = heads[count-1];
1213+
index -= count;
12041214
}
12051215
}
12061216

0 commit comments

Comments
 (0)