Bad write file performance on iMX6 with WinEC7

We are currently porting our embedded application from WinCE 6.0 / PXA320 to a newer system WinEC7 / iMX6S. Unfortunately we have performance issues on WinEC7, it is just half of the speed of the older system when writing files on the FlashDisk. Is there a reason for this? Can the performance be improved?

Here is our test code:

void FileSystemTest::test_createFiles()
{
    const float LINE_NUMBERS = 10;
    const int MIN_EXPONENT = 1;
    const int MAX_EXPONENT = 5;

    const std::string TEST_FILE_NAME = "testfile.txt";
    std::string filePath("\\FlashDisk\\");

    std::string file = filePath + "Duration.txt"; //store the 
    FILE *fp = fopen(file.c_str(), "w+"); //in milliseconds
    
    fprintf(fp,"Create Files unit test (UtilitiesTest)\n");

    fprintf(fp,"Write lines without closing file\n");
    for(int exponent = MIN_EXPONENT; exponent < MAX_EXPONENT; exponent++)
    {
        DWORD startTime = GetTickCount();
        int no_of_lines = (int)pow(LINE_NUMBERS, exponent);
        // delete file if existing
        PMT::FileSystem::deleteFile( filePath + TEST_FILE_NAME.c_str() );
        test_createFile(filePath + TEST_FILE_NAME, no_of_lines, false);
        DWORD endTime = GetTickCount();
        DWORD duration = endTime - startTime; // duration in milliseconds
        fprintf(fp,"Duration for %d lines: %d ms\n",no_of_lines, duration);
    }

    fprintf(fp,"Write lines with closing file\n");
    for(int exponent = MIN_EXPONENT; exponent < MAX_EXPONENT; exponent++)
    {
        DWORD startTime = GetTickCount();
        int no_of_lines = (int)pow(LINE_NUMBERS, exponent);
        // delete file if existing
        PMT::FileSystem::deleteFile( filePath + TEST_FILE_NAME.c_str() );
        test_createFile(filePath + TEST_FILE_NAME, no_of_lines, true);
        DWORD endTime = GetTickCount();
        DWORD duration = endTime - startTime; // duration in milliseconds
        fprintf(fp,"Duration for %d lines: %d ms\n",no_of_lines, duration);
    }
    // delete file
    PMT::FileSystem::deleteFile( filePath + TEST_FILE_NAME.c_str() );
    fclose(fp);
}

void FileSystemTest::test_createFile(const std::string fileName, const int lineNumbers, bool closeFileAfterLine)
{
    FILE *fp = NULL;
    if (!closeFileAfterLine)
    {
        fp = fopen(fileName.c_str() , "w");
    }
    
    for(int i = 0; i < lineNumbers; i++)
    {
        if (closeFileAfterLine)
        {
            fp = fopen(fileName.c_str() , "a");
        }
        CPPUNIT_ASSERT( fp != NULL );
        fprintf(fp, "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n");
        if (closeFileAfterLine)
        {
            fclose(fp);
        }
    }

    if (!closeFileAfterLine)
    {
        fclose(fp);
    }
}

Currently on flashdisk we disable the write-back cache, this means that data is written on the eMMC as soon as the application calls the write function. For small write operations, this has some overhead because the operation is completed only when data is actually stored on flash (on the other side it grants that data is not lost in case of a power failure etc.).
You may enable cache using the registry or you can add an intermediate buffering mechanism to write larger chunks of data (a sector on eMMC is 512 bytes).

I did a quick test, setting

[HKEY_LOCAL_MACHINE\SYSTEM\StorageManager\Profiles\BootMMC\FATFS]
EnableWriteBack=dword:1

This shows a good improvement on the test that does not close the file, and same timings for the test that always closes it (this will flush the cache anyway).
You can find test results here: https://share.toradex.com/l3hdymc81p6feuw?direct
Duration_WB.txt contains test results with writeback cache enabled.
I had to change your code to remove dependencies on extra classes not included in the code, but that should not change the results.

We tried the registry setting you suggested but it does not really resolve our performance issues.
We found some other benchmark tests from TI which also show slower performance for WinEC7:

Is it possible that file access in the new operating system is simply slower than in the old one?

On imx6 we don’t have CE6, so we can’t do such a comparison, but for sure those data show a decrease in performances.
Write performance is also influenced by filesystem. If you used CE5/6 and FAT then performances are quite good as long as the storage does not contain much data and is not fragmented. They get much worse when storage is almost full and fragmented (for FAT worst case is that you need to read all sectors -1 to find a free one). ExFAT uses maps of free sectors that require some extra operations to stay up to date, but grant that write times are the same independently from fragmentation and space used. Probably this can explain those results.
What kind of files are you accessing? Having them stored in RAM (using ramdisk to avoid performance bottlenecks of object store) and saving them periodically in flash could be an option?
What’s the improvement you had by enabling write-back cache (if you had any)?

Our data is kept in SQLite databases and the files can be up to a few MB in size. The fix you described improved the write performance by 10-20% depending on the data size. However, this is not enough to compensate the lower performance we see with iMX6/WinEC7.

Our database access is not optimized for performance yet so we can improve the speed by using less transactions. Using that approach we have a workaround for the original problem.