rust-embedded-community / embedded-storage

An Embedded Storage Abstraction Layer
Apache License 2.0
63 stars 21 forks source link

Optimize OverlapIterator #53

Closed aurelj closed 1 month ago

aurelj commented 3 months ago

In my project, I noticed that writing to flash was pretty slow, so I tried to trace it out, and I pin-pointed the culprit to the OverlapIterator.

This PR optimizes the OverlapIterator so that in my test case, writing a 400 kB file to flash went down from 204 s to 14 s ! So basically, I went from unusable to good enough with just this change.

Note that to optimize the OverlapIterator, it needs to know the start and end of the Region, so I needed to add those the the Region trait. So this is a breaking change and will require a version bump.

I'm not sure how do you prefer to handle this version bump ? Would you like me to include it in this PR ? (I propose to bump embedded-storage to 0.4.0)

For the record, my test case is running on a STM32F407 with an external SPI flash (W25Q32) handled by the w25q32jv crate (implementing embedded-storage) and formatted as FAT32 using embedded-fatfs. The whole thing is running with embassy and I'm downloading the file thru HTTP on the ethernet port using reqwless.