Abandoned data-backed cache, use indirect lfs3_data_t on stack
This abandons the data-backed cache idea due to concerns around
readability and maintainability. Mixing const/mutable buffers in
lfs3_data_t was not great.
Instead, we now just allocate an indirect lfs3_data_t on the stack in
lfs3_file_sync_ to avoid the previous undefined behavior.
This actually results in less stack usage total, due to lfs3_file_t
allocations in lfs3_set/read, and avoid the more long-term memory cost
in lfs3_file_t:
code stack ctx
before: 36832 2376 684
after: 36840 (+0.0%) 2368 (-0.3%) 684 (+0.0%)
Oh. And lfs3_file_sync_ isn't even on the stack hot-path, so this is a
net benefit over the previous cache -> data cast:
code stack ctx
before sa: 36844 2368 684
after sa: 36840 (-0.0%) 2368 (+0.0%) 684 (+0.0%)
Still less cool though.
This commit is contained in:
@@ -636,7 +636,6 @@ typedef struct lfs3_data {
|
||||
lfs3_size_t size;
|
||||
union {
|
||||
const uint8_t *buffer;
|
||||
uint8_t *buffer_;
|
||||
struct {
|
||||
lfs3_block_t block;
|
||||
lfs3_size_t off;
|
||||
@@ -742,11 +741,14 @@ typedef struct lfs3_file {
|
||||
#endif
|
||||
|
||||
// in-RAM cache
|
||||
//
|
||||
// note this lines up with lfs3_data_t's buffer representation
|
||||
struct {
|
||||
#ifndef LFS3_KVONLY
|
||||
lfs3_off_t pos;
|
||||
#endif
|
||||
lfs3_data_t d;
|
||||
lfs3_off_t size;
|
||||
uint8_t *buffer;
|
||||
} cache;
|
||||
|
||||
// on-disk leaf bptr
|
||||
|
||||
Reference in New Issue
Block a user