WHY????? Why does SPIFFS slow down....
Posted: Thu Mar 08, 2018 7:37 pm
the more you write files, the slower it gets!!!!! Its insane, I have been battling this from 2.0.0 to 2.4.0 its always the same, I have changed code around, and code logic, etc....
Can not make it work.
Run this Arduino code (it will format your SPIFFS) and you will see it get slower and slower......
WHY??
Can not make it work.
Run this Arduino code (it will format your SPIFFS) and you will see it get slower and slower......
WHY??
Code: Select all
//******************************************************************************
// SPIFFS TEST
//******************************************************************************
#include <FS.h>
void setup() {
Serial.begin(115200);
SPIFFS.begin();
}
void removeAll() {
#if 0
SPIFFS.remove("/1");
SPIFFS.remove("/2");
SPIFFS.remove("/3");
SPIFFS.remove("/4");
SPIFFS.remove("/5");
#endif
SPIFFS.remove("/5");
SPIFFS.remove("/4");
SPIFFS.remove("/3");
SPIFFS.remove("/2");
SPIFFS.remove("/1");
}
#define SECTOR 256
char buf[SECTOR];
void make(String f, int n) {
int time;
int packet = 0;
Serial.printf("making %s length = %d\n", f.c_str(), n);
// SPIFFS.remove(f);
File pESP = SPIFFS.open(f, "w");
time = millis();
while (n > 0) {
if((packet++ % 20) == 0) {
Serial.println(millis()-time);
time = millis();
}
int bytes = (n > SECTOR) ? SECTOR : n;
n -= SECTOR;
//memset(buf, n, sizeof(buf));
pESP.write((uint8_t*)buf, bytes);
yield();
}
pESP.close();
}
void loop() {
uint32_t first, second, third, fourth;
Serial.printf("\nFormatting...\n");
SPIFFS.format();
if(0) {
// was used to read and write at same time for tests...
//make("/temp", 1234 + 12112 + 200220 + 454030 + 20220 + 100100);
//fp = SPIFFS.open("temp", "r");
//fp.seek(0, SeekEnd);
//fp.position();
//fp.seek(0, SeekSet);
}
Serial.println("first run");
uint32_t startTime = millis();
make("/1", 1234);
make("/2", 12112);
make("/3", 200220);
make("/4", 454030);
make("/5", 20220);
make("/6", 100100);
first = millis() - startTime;
removeAll();
Serial.println("second run");
startTime = millis();
make("/1", 1234);
make("/2", 12112);
make("/3", 200220);
make("/4", 454030);
make("/5", 20220);
make("/6", 100100);
second = millis() - startTime;
removeAll();
Serial.println("third run");
startTime = millis();
make("/1", 1234);
make("/2", 12112);
make("/3", 200220);
make("/4", 454030);
make("/5", 20220);
make("/6", 100100);
third = millis() - startTime;
removeAll();
Serial.println("fourth run");
startTime = millis();
make("/1", 1234);
make("/2", 12112);
make("/3", 200220);
make("/4", 454030);
make("/5", 20220);
make("/6", 100100);
fourth = millis() - startTime;
Serial.printf("Time first = %dms\n", first);
Serial.printf("Time second = %dms\n", second);
Serial.printf("Time third = %dms\n", third);
Serial.printf("Time fourth = %dms\n", fourth);
for(;;) yield();
}