esp-idf: SD card fseek is much slower on esp-idf 5.0 comparing to 4.4 (IDFGH-9089)
Answers checklist.
- I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
- I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
- I have searched the issue tracker for a similar issue and not found a similar issue.
General issue report
Hello. I got strange problem after updating esp-idf from 4.4 to 5.0 (release branch) SD card reading time increased from 124ms to 1153ms. There is no difference in code or configuration, also content of SD card was not changed.
Main problem: Execution time of fseek raised from 2ms to 81ms, this is clearly visible on difference between timestamp t1-t
Important part of code
t = esp_timer_get_time();
lastline = currentLine;
fseek(f,ef->lineLength*(currentLine-1), SEEK_SET);
t1 = esp_timer_get_time();
fgets(line, sizeof(line), f);
t2 = esp_timer_get_time();
valueInLine = strtoll(line,&pEnd,10);
ESP_LOGI(TAG, "Line :%u val:%lld", currentLine, valueInLine);
t3 = esp_timer_get_time();
ESP_LOGI(TAG, "t-t1:%llu, t1-t2:%llu, t2-t3:%llu,",(t1-t)/1000, (t2-t1)/1000, (t3-t2)/1000 );

I was trying
- change task priority
- running on different core
- change data size
- changing max_transfer_sz
- change to fast seek CLMT buffer and enable fast seek algorithm
i’m using fseek to quiclkly jump in big file between lines. reading one by one is to slow.
Thanks in advance for any ideas.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 19
Yes, for me it is fine to close this one as issue is solved by woraround. Thank you @adokitkat for you support
Workaround: In case of SPI SD communication use CS defined as -1 (not used) to avoid problem with long fseek() execution. This workaround will work only if there is only one slave device on SPI bus connected.
@adokitkat I took your example and run without any changes, also without running espconfig or erase. Every example i’m running in vscode because i got some environmental problems when i’m trying to run from cmd.
i’m trying to figure out which option is causing this problem, because on clean example from you i got correct times, so it seems to be related to project config