arduino-libraries / SD

SD Library for Arduino
http://arduino.cc/
GNU General Public License v3.0
182 stars 154 forks source link

Fixed openNextFile() speed in case of large directories. #94

Closed dikdom closed 3 years ago

dikdom commented 3 years ago

In case of large directories the SD::openNextFile() iterates through the files and opens them one by one. It calls SdFile::open() by name, so the open() method also iterates through the directory until it finds the selected file. Instead let's keed track the directory index (position within the directory) and open the file by this index. This speeds up the iteration on large directories dramatically.

Also a typo is fixed in the README.adoc. From the author, you shall remove my name.

CLAassistant commented 3 years ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Vass seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

github-actions[bot] commented 3 years ago

Memory usage change @ dc2ea3e36b3ed14ca37e19327996b3d1abc5e4c3

Board flash % RAM for global variables %
arduino:avr:leonardo :small_red_triangle: 0 - +182 0.0 - +0.63 0 - 0 0.0 - 0.0
arduino:avr:mega :small_red_triangle: 0 - +182 0.0 - +0.07 0 - 0 0.0 - 0.0
arduino:avr:nano :small_red_triangle: 0 - +182 0.0 - +0.59 0 - 0 0.0 - 0.0
arduino:mbed_nano:nano33ble :small_red_triangle: 0 - +64 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect :small_red_triangle: 0 - +88 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m4 :small_red_triangle: 0 - +64 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7 :small_red_triangle: 0 - +64 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:megaavr:nona4809 :small_red_triangle: 0 - +182 0.0 - +0.37 0 - 0 0.0 - 0.0
arduino:sam:arduino_due_x_dbg :small_red_triangle: 0 - +80 0.0 - +0.02 N/A N/A
arduino:samd:mkrzero :small_red_triangle: 0 - +92 0.0 - +0.04 0 - 0 0.0 - 0.0
Click for full report table Board|examples/CardInfo
flash|%|examples/CardInfo
RAM for global variables|%|examples/Datalogger
flash|%|examples/Datalogger
RAM for global variables|%|examples/DumpFile
flash|%|examples/DumpFile
RAM for global variables|%|examples/Files
flash|%|examples/Files
RAM for global variables|%|examples/NonBlockingWrite
flash|%|examples/NonBlockingWrite
RAM for global variables|%|examples/ReadWrite
flash|%|examples/ReadWrite
RAM for global variables|%|examples/listfiles
flash|%|examples/listfiles
RAM for global variables|% -|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|- arduino:avr:leonardo|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|182|0.63|0|0.0 arduino:avr:mega|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|182|0.07|0|0.0 arduino:avr:nano|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|182|0.59|0|0.0 arduino:mbed_nano:nano33ble|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|64|0.01|0|0.0 arduino:mbed_nano:nanorp2040connect|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|88|0.0|0|0.0 arduino:mbed_portenta:envie_m4|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|64|0.01|0|0.0 arduino:mbed_portenta:envie_m7|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|64|0.01|0|0.0 arduino:megaavr:nona4809|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|182|0.37|0|0.0 arduino:sam:arduino_due_x_dbg|0|0.0|N/A|N/A|0|0.0|N/A|N/A|0|0.0|N/A|N/A|0|0.0|N/A|N/A|0|0.0|N/A|N/A|0|0.0|N/A|N/A|80|0.02|N/A|N/A arduino:samd:mkrzero|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|92|0.04|0|0.0
Click for full report CSV ``` Board,examples/CardInfo
flash,%,examples/CardInfo
RAM for global variables,%,examples/Datalogger
flash,%,examples/Datalogger
RAM for global variables,%,examples/DumpFile
flash,%,examples/DumpFile
RAM for global variables,%,examples/Files
flash,%,examples/Files
RAM for global variables,%,examples/NonBlockingWrite
flash,%,examples/NonBlockingWrite
RAM for global variables,%,examples/ReadWrite
flash,%,examples/ReadWrite
RAM for global variables,%,examples/listfiles
flash,%,examples/listfiles
RAM for global variables,% arduino:avr:leonardo,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,182,0.63,0,0.0 arduino:avr:mega,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,182,0.07,0,0.0 arduino:avr:nano,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,182,0.59,0,0.0 arduino:mbed_nano:nano33ble,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,64,0.01,0,0.0 arduino:mbed_nano:nanorp2040connect,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,88,0.0,0,0.0 arduino:mbed_portenta:envie_m4,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,64,0.01,0,0.0 arduino:mbed_portenta:envie_m7,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,64,0.01,0,0.0 arduino:megaavr:nona4809,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,182,0.37,0,0.0 arduino:sam:arduino_due_x_dbg,0,0.0,N/A,N/A,0,0.0,N/A,N/A,0,0.0,N/A,N/A,0,0.0,N/A,N/A,0,0.0,N/A,N/A,0,0.0,N/A,N/A,80,0.02,N/A,N/A arduino:samd:mkrzero,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,92,0.04,0,0.0 ```
dikdom commented 3 years ago

I have agreed the CLA. I am a GitHub user.