Very slow writing to file #12442
-
I am not sure what i am doing wrong, but I am experiencing very slow writing to a file located on built-in flash of Pico. I measured the time it takes to write with the ticks_us diff, and it takes over 3 seconds! Please tell me I am doing something wrong and this should be much faster... with open('myfile', mode='r+b') as file:
file.seek(position)
t = time.ticks_us()
file.write(myByteArray[128:256])
print(time.ticks_diff(time.ticks_us(), t)) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
@czarnikjak Is this easily reproducible? Does the slow write happen every time. Are you able to provide a simple script I can run here to test the same thing? For some background... 3 seconds seems too long. Sometimes writes will be slower as the LittleFS filesystem has to rebalance the flash and do housekeeping, but this should not occur on every write. |
Beta Was this translation helpful? Give feedback.
-
It seems to be a matter of the file system. With LFS I get the similar numbers on RP2 or e.g. MIMXRT. With a FAT file system the write times are consistent at about 140ms. It seems that with LFS the whole tail of the file is rewritten. |
Beta Was this translation helpful? Give feedback.
-
FYI @czarnikjak @robert-hh this behaviour in LittleFS is described here littlefs-project/littlefs#244 Suggested workaround is to break your data up into smaller files. |
Beta Was this translation helpful? Give feedback.
FYI @czarnikjak @robert-hh this behaviour in LittleFS is described here littlefs-project/littlefs#244
Suggested workaround is to break your data up into smaller files.