Skip to content
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

[BUG] SD card navigation is unusably slow #27247

Open
1 task done
dbuezas opened this issue Jul 6, 2024 · 1 comment
Open
1 task done

[BUG] SD card navigation is unusably slow #27247

dbuezas opened this issue Jul 6, 2024 · 1 comment

Comments

@dbuezas
Copy link
Contributor

dbuezas commented Jul 6, 2024

Did you test the latest bugfix-2.1.x code?

Yes, and the problem still exists.

Bug Description

When navigating the SD card from the UI (SSD1309), the UI becomes unusably slow even though I have a very speedy mcu (550MHz, skr3).

The problem is not there when I use SDCARD_SORT_ALPHA, but I wish the latest files would show at the top instead of the files being sorted by name

#define SDCARD_SORT_ALPHA

  // SD Card Sorting options
  #if ENABLED(SDCARD_SORT_ALPHA)
    #define SDSORT_REVERSE     true  // Default to sorting file names in reverse order.
    #define SDSORT_LIMIT       256     // Maximum number of sorted items (10-256). Costs 27 bytes each.
    #define SDSORT_FOLDERS     -1     // -1=above  0=none  1=below
    #define SDSORT_GCODE       false  // Enable G-code M34 to set sorting behaviors: M34 S<-1|0|1> F<-1|0|1>
    #define SDSORT_USES_RAM    true   // Pre-allocate a static array for faster pre-sorting.
    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
    #define SDSORT_CACHE_NAMES true   // Keep sorted items in RAM longer for speedy performance. Most expensive option.
    #define SDSORT_DYNAMIC_RAM false  // Use dynamic allocation (within SD menus). Least expensive option. Set SDSORT_LIMIT before use!
    #define SDSORT_CACHE_VFATS 5      // Maximum number of 13-byte VFAT entries to use for sorting.
                                      // Note: Only affects SCROLL_LONG_FILENAMES with SDSORT_CACHE_NAMES but not SDSORT_DYNAMIC_RAM.
  #endif

  // Allow international symbols in long filenames. To display correctly, the
  // LCD's font must contain the characters. Check your selected LCD language.
  #define UTF_FILENAME_SUPPORT

  #define LONG_FILENAME_HOST_SUPPORT    // Get the long filename of a file/folder with 'M33 <dosname>' and list long filenames with 'M20 L'
  #define LONG_FILENAME_WRITE_SUPPORT   // Create / delete files with long filenames via M28, M30, and Binary Transfer Protocol
  #define M20_TIMESTAMP_SUPPORT         // Include timestamps by adding the 'T' flag to M20 commands

  #define SCROLL_LONG_FILENAMES         // Scroll long filenames in the SD card menu

Bug Timeline

At least since Nov 2023, possibly since forever?

Expected behavior

The UI navigates files fast (possibly by caching them like with SDCARD_SORT_ALPHA but without sorting them)

Actual behavior

UI unusably slow while navigating sd card without SDCARD_SORT_ALPHA

Steps to Reproduce

No response

Version of Marlin Firmware

Latest bugfix 2.1.x

Printer model

UM2

Electronics

SKR3

LCD/Controller

SSD1309

Other add-ons

No response

Bed Leveling

ABL Bilinear mesh

Your Slicer

Other (explain below)

Host Software

None

Don't forget to include

  • A ZIP file containing your Configuration.h and Configuration_adv.h.

Additional information & file uploads

Archive.zip

@dbuezas
Copy link
Contributor Author

dbuezas commented Jul 6, 2024

I hacked this together to keep the file list cache without actually sorting by name.
BTW, any reason to use bubble sort here? heap sort has better time complexity, also sorts in-place (i.e low ram impact) and is almost as simple

diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h
index dd1f036cff..08c6a1ab71 100644
--- a/Marlin/Configuration_adv.h
+++ b/Marlin/Configuration_adv.h
@@ -1797,6 +1797,7 @@

   // SD Card Sorting options
   #if ENABLED(SDCARD_SORT_ALPHA)
+    #define SDSORT_NO_SORT     true  // Keep cache but dont actually sort
     #define SDSORT_REVERSE     true  // Default to sorting file names in reverse order.
     #define SDSORT_LIMIT       256     // Maximum number of sorted items (10-256). Costs 27 bytes each.
     #define SDSORT_FOLDERS     -1     // -1=above  0=none  1=below
diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp
index dadb1bcefc..de7fca22b8 100644
--- a/Marlin/src/sd/cardreader.cpp
+++ b/Marlin/src/sd/cardreader.cpp
@@ -1262,7 +1262,7 @@ void CardReader::cdroot() {

         // Init sort order.
         for (int16_t i = 0; i < fileCnt; i++) {
-          sort_order[i] = i;
+          sort_order[i] = (SDSORT_REVERSE && SDSORT_NO_SORT) ? fileCnt - i - 1: i;
           // If using RAM then read all filenames now.
           #if ENABLED(SDSORT_USES_RAM)
             selectFileByIndex(i);
@@ -1281,6 +1281,7 @@ void CardReader::cdroot() {

         // Bubble Sort
         for (int16_t i = fileCnt; --i;) {
+          TERN1(SDSORT_NO_SORT, break;)
           bool didSwap = false;
           int16_t o1 = sort_order[0];
           #if DISABLED(SDSORT_USES_RAM)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant