Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@qrvd
Copy link
Contributor

@qrvd qrvd commented Oct 22, 2025

Before moving or copying files, CopyLoader traverses the full directory trees two times to calculate the total file size. This traversal is now only done once and generatorized to prevent Ranger from freezing when there is a large number of files to move. File moves that require just a rename will also yield now, again to avoid a UI hiccup when there are many items to move or we're on a slow/networked file system.

ISSUE TYPE

x Bug fix

RUNTIME ENVIRONMENT

  • Operating system and version:
  • Terminal emulator and version: Tilix 1.9.5
  • Python version: 3.11.2
  • Ranger version/commit: master
  • Locale: en_US.UTF-8

CHECKLIST

  • The CONTRIBUTING document has been read [REQUIRED]
  • All changes follow the code style [REQUIRED]
  • All new and existing tests pass [REQUIRED]
  • Changes require config files to be updated
    • Config files have been updated
  • Changes require documentation to be updated
    • Documentation has been updated
  • Changes require tests to be updated
    • Tests have been updated

DESCRIPTION

  • shutil_generatorized.move(): yield after renaming
  • CopyLoader._calculate_size(): yield after calculating the size of a file or listing a directory
  • CopyLoader.generate(): calculate the file size by traversing the tree only once. Calculate self.percent in terms of bytes since this is what shutil_generatorized gives us

MOTIVATION AND CONTEXT

Traversing the full tree of files to be moved can take a lot of time, rendering Ranger completely unresponsive. Such work should be generatorized.

We also fix the percentage calculation and no longer traverse the tree twice, see commit message: 3e39b67

shutil_generatorized.move() will yield periodically when moving files, except when a file can be renamed to its destination. Instead it should probably always yield since renaming files is an I/O operation with performance impact depending on how slow the filesystem is or the number of files being renamed.

TESTING

Tested by moving directories containing 100K+ files in total, from one folder to another. After the changes, the freezes no longer occur.

Changes should improve the performance of the :paste command. No adverse changes to the rest of the codebase since only CopyLoader uses shutil_generatorized.

qrvd added 3 commits October 22, 2025 17:53
The percentage bar was always calculated in terms of
number of bytes, not number of units `step`.
Mixing the units causes a visual bug where the percentage
bar doesn't reflect actual progress.

This fix also improves performance since we don't traverse
the tree twice to calculate the total size in different units.
Fixes performance bug where the UI could temporarily freeze
when copying or moving large trees of files, because
the size calculation would never yield.
Renaming is an I/O operation, so it could take a significant amount
of time on networked filesystems. We should probably yield to keep
the UI running even under such cases.
@qrvd qrvd marked this pull request as ready for review October 22, 2025 20:54
@qrvd
Copy link
Contributor Author

qrvd commented Oct 22, 2025

# TODO: Don't calculate size when renaming (needs detection)
for size in self._calculate_size():
yield
size = max(1, size)
size_str = " (" + human_readable(size) + ")"

Ranger does a lot of I/O here to pre-calculate the total size of files moved, just for the progress bar. Is it really worth it or shouldn't we remove it / make it a setting? On my system it makes a huge difference to just skip this step and go ahead with the move/copy.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.