-
Notifications
You must be signed in to change notification settings - Fork 7.6k
FS: Performance improvements in vfs_api #7541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is functionally equivalent but better performance. No obvious bugs introduced. LGTM.
Hi @BlueAndi @mrengineer7777, I did a quick test and creating 24 dirs with this PR take around 5400ms (was around 2000 ms before). Do yo have any data that the speed has improved? Or some sketch to test it myself? Thanks |
@P-R-O-C-H-Y I have not tested the code, only reviewed proposed changes. Swapping sprintf for strcpy + strcat should be faster. That said, I did read this weekend that strcat rescans the target string before appending. The fastest implementation here would be to use pointers. e.g. for the mkdir function.
PR:
Faster (theoretical, untested):
Result will be in "temp". As a bonus you can calculate the string length as temp-ptr. |
@P-R-O-C-H-Y I measured by walking recursively through the directories and files (LittleFS) by using open() and openNextFile() in a existing project. I will move it to a separate sketch and measure creating directories and files too. |
@P-R-O-C-H-Y Can you please test with it on your side? https://github.com/BlueAndi/fsTest Original:
Improved:
I hope I did not any mistake!? :-) |
Hi @BlueAndi, I have tested your sketch with ESP32-DevKitC for LittleFS lib and edited sketch for testing on ESP32-WroverKit with SD Library. These are the results. LITTLEFS library ORIGINAL:
With changes from PR:
SD LIBRARY ORIGINAL:
With changes from PR:
From my side, I did not get the result as you did. On what chip did you test? I will try it on different chips, but for sure I can say, that for SD lib, the files + directories creation is a lot worse than it was before. But I don't get why is behaving differently. |
I tested it with a esp32doit-devkit-v1, further detail:
In our first two measurements with LittleFS I can't see really a difference. Hmm ... I can't see the difference to the SD library. Will try on another board with a esp32-s3. |
With the Lilygo T-Display S3 the difference is not so high, but still there. Original:
Improved:
|
…itional avoid creating temporary String objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did another test with SD card running on 40 MHz, and got better performance with this PR.
ORIGINAL CODE - SD card 40 MHz:
[ 53][I][fs_test.ino:161] loop(): [main] Creating directories and files ...
[ 53][I][fs_test.ino:162] loop(): [main] Directories per level: 5
[ 55][I][fs_test.ino:163] loop(): [main] Directory depth : 5
[ 61][I][fs_test.ino:164] loop(): [main] Files per directory : 5
[ 4531][I][fs_test.ino:175] loop(): [main] --> Duration: 4 s 464 ms
[ 4532][I][fs_test.ino:179] loop(): [main] Walking through directories recursively ...
[ 7654][I][fs_test.ino:184] loop(): [main] --> Duration: 3 s 120 ms
WITH CHANGES FROM PR - SD card 40 MHz:
[ 93][I][fs_test.ino:161] loop(): [main] Creating directories and files ...
[ 93][I][fs_test.ino:162] loop(): [main] Directories per level: 5
[ 94][I][fs_test.ino:163] loop(): [main] Directory depth : 5
[ 101][I][fs_test.ino:164] loop(): [main] Files per directory : 5
[ 4451][I][fs_test.ino:175] loop(): [main] --> Duration: 4 s 344 ms
[ 4451][I][fs_test.ino:179] loop(): [main] Walking through directories recursively ...
[ 7210][I][fs_test.ino:184] loop(): [main] --> Duration: 2 s 756 ms
But I still cannot understand, why it was that much slower with SD card running on 20 MHz as I posted before. The changes should improve the speed.
Lets merge this PR, thanks @BlueAndi for the PR and for providing the test sketch 👍
@P-R-O-C-H-Y You are welcome and its always good that someone independend review the stuff. Thanks for your effort as well! |
@BlueAndi Btw. I work for Espressif. My part is in Arduino project and mostly taking care of FS libs + some peripherals. |
Performance improvements by replacing sprintf with strcpy/strcat. Additional avoid creating temporary String objects.