#68 When scanning directories, why bother sorting entries?

closed-wont-fix
None
5
2012-01-12
2012-01-10
Mikhail Teterin
No

minidlna invokes scandir(3) with alphasort as the last argument. This is redundant -- there is no need to sort the directories entries selected, it does not matter, in which order they will be processed. Although Linux' man-page for scandir is silent on this, both FreeBSD and Solaris document, that if the supplied comparison function is given as NULL, no sorting will occur.

The patch below should save some CPU-cycles, when scanning content-directories.

Discussion

  • Pass NULL instead of alphasort as the last argument to scandir(3).

     
    Attachments
    • assigned_to: nobody --> jmaggard
     
  • Justin Maggard
    Justin Maggard
    2012-01-12

    • status: open --> closed-wont-fix
     
  • Justin Maggard
    Justin Maggard
    2012-01-12

    I'm all for saving CPU cycles where it makes sense. But sorting is well worth the extra CPU cycles, IMHO, for the following reasons:
    1) Prettier log files. :)
    2) Users can get a much better idea of how far along we are in the scanning process.
    3) Gives us better unsorted DLNA query results.
    4) Can help in first-level debugging, since users can tell what file is being scanned if they run into a issue.