Refactor: Reduce File Browser Sorting #119103

Closed
Harley Acheson wants to merge 3 commits from Harley/blender:FileSorting into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Eliminate multiple worst-case scenario file list sorting.


This sounds improbable, so this needs some explanation.

On my Windows computer, when we ask for a directory file listing using API call FindNextFileW the items come out in alphabetical order (for NTFS and CDFS). So the list is A-Z

But when we are using that function to assemble the list - in bli_builddir - we add each item using addhead so the list becomes alphabetically backwards . Z-A

Once that is done we call qsort - also in bli_builddir - on the list to make it (naturally) alphabetically forward (and also put folders first). Because of the previous step we have made this sort almost as difficult as possible. A-Z

Now that we have this alphabetical list we then load that into file browser lists, but we do so by going through the list in reverse order - in filelist_readjob_list_dir. Z-A

After this the file listings are then sorted again as the user wishes. And if this is forward alpha order then we are again making this sort as difficult as possible. But now finally A-Z

So A-Z -> Z-A -> A-Z -> Z-A -> A-Z

This PR keeps the items in order before sorting in bli_builddir, then processes the items in order in filelist_readjob_list_dir, eliminating the reversals.

Note that I have reversed the processing order inside filelist_readjob_list_dir instead of merely changing a single addtail to an addhead. This is because there could (later) be utility in going through the list in order, especially since it is sorted. For example if we ever want to collapse image sequences.

Eliminate multiple worst-case scenario file list sorting. --- This sounds improbable, so this needs some explanation. On my Windows computer, when we ask for a directory file listing using API call `FindNextFileW ` the items come out in alphabetical order (for NTFS and CDFS). So the list is A-Z But when we are using that function to assemble the list - in `bli_builddir` - we add each item using addhead so the list becomes alphabetically backwards . Z-A Once that is done we call qsort - also in `bli_builddir` - on the list to make it (naturally) alphabetically forward (and also put folders first). Because of the previous step we have made this sort almost as difficult as possible. A-Z Now that we have this alphabetical list we then load that into file browser lists, but we do so by going through the list in **reverse order** - in `filelist_readjob_list_dir`. Z-A After this the file listings are then sorted again as the user wishes. And if this is forward alpha order then we are again making this sort as difficult as possible. But now finally A-Z **So A-Z -> Z-A -> A-Z -> Z-A -> A-Z** This PR keeps the items in order before sorting in bli_builddir, then processes the items in order in filelist_readjob_list_dir, eliminating the reversals. Note that I have reversed the processing order inside `filelist_readjob_list_dir` instead of merely changing a single addtail to an addhead. This is because there could (later) be utility in going through the list in order, especially since it is sorted. For example if we ever want to collapse image sequences.
Harley Acheson added 1 commit 2024-03-06 00:37:49 +01:00
276e8b6f89 Refactor: Reduce File Browser Sorting
Eliminate multiple worst-case scenario file list sorting.
Harley Acheson added this to the User Interface project 2024-03-06 01:03:34 +01:00
Harley Acheson requested review from Hans Goudey 2024-03-06 01:18:23 +01:00
Hans Goudey reviewed 2024-03-06 17:03:25 +01:00
Hans Goudey left a comment
Member

First of all, nice find! Improving this does seem nice. And if there's sorting going on after every step, changing the order of the lists in intermediate cases should matter.

Two main thoughts though:

  1. What is the motivating goal of the PR? If it's code cleanup, that's nice, but apart from replacing the old while (i--) style for loop, there isn't much improvement. If it's performance, it would be good to include some performance numbers in a large directory or something.
  2. The PR description has much more information than the final commit message here. I think there could be a balance, so someone reading the commit in a few years would at least have some understanding of why "addhead" was changed to "addtail"
First of all, nice find! Improving this does seem nice. And if there's sorting going on after every step, changing the order of the lists in intermediate cases should matter. Two main thoughts though: 1. What is the motivating goal of the PR? If it's code cleanup, that's nice, but apart from replacing the old `while (i--)` style for loop, there isn't much improvement. If it's performance, it would be good to include some performance numbers in a large directory or something. 2. The PR description has _much_ more information than the final commit message here. I think there could be a balance, so someone reading the commit in a few years would at least have some understanding of why "addhead" was changed to "addtail"
@ -3141,0 +3136,4 @@
entries_num++;
}
if (files) {
Member

It looks like moving the if (files) check is an unrelated cleanup? The diff would be clearer without that.

It looks like moving the `if (files)` check is an unrelated cleanup? The diff would be clearer without that.
Harley marked this conversation as resolved
Harley Acheson added 1 commit 2024-03-06 18:26:27 +01:00
Harley Acheson added 1 commit 2024-03-06 18:28:27 +01:00
Author
Member

@HooglyBoogly

All good points. I updated this PR so that it is the minimum changes to stop the list reversals.

There really isn't anything here that would be a measurable performance change in regular usage. I was only amused while looking around in there.

My only motivation was in taking some notes regarding a right-click select suggestion and wanted to remind myself at where would would need sorting. At a place I expected an unsorted order I saw a reversed alpha natural sort so followed the flow from the OS on through.

@HooglyBoogly All good points. I updated this PR so that it is the _minimum_ changes to stop the list reversals. There really isn't anything here that would be a measurable performance change in regular usage. I was only amused while looking around in there. My only motivation was in taking some notes regarding a [right-click select suggestion](https://blender.community/c/rightclickselect/LJvv/) and wanted to remind myself at where would would need sorting. At a place I expected an unsorted order I saw a reversed alpha natural sort so followed the flow from the OS on through.
Member

There really isn't anything here that would be a measurable performance change in regular usage. I was only amused while looking around in there.

Okay, maybe this is a party-pooper stance, but if there is no performance gain and no improvement in code quality, I don't get the point of this PR. I think generally each commit should have a clear motivation-- as it stands this one doesn't really.

>There really isn't anything here that would be a measurable performance change in regular usage. I was only amused while looking around in there. Okay, maybe this is a party-pooper stance, but if there is no performance gain and no improvement in code quality, I don't get the point of this PR. I think generally each commit should have a clear motivation-- as it stands this one doesn't really.
Author
Member

No worries.

No worries.
Harley Acheson closed this pull request 2024-03-06 20:41:25 +01:00

Pull request closed

Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#119103
No description provided.