mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 18:42:34 +01:00
The orphaned resource cleanup listed the resource tree through
`anyio.Path`, which dispatches to a worker thread for every entry it
yields and again for every `is_dir()` call. On a library with ~30k ROM
resource directories that is ~60k thread round trips to read data the
directory listing already contains.
Measured on a 30,262-directory library (Raspberry Pi 4, ext4):
anyio iterdir + is_dir() 50.3s
os.scandir 0.15s
`os.scandir` reports the entry type from the directory read itself, so
no per-entry stat is needed. The walk moves into a helper run once via
`asyncio.to_thread`, keeping the event loop free while doing the whole
traversal in a single thread hop rather than tens of thousands.
Cold and warm runs of the old code were within 1% of each other, so this
was thread-dispatch overhead rather than disk I/O.
A directory that cannot be listed now logs and yields an empty set
instead of aborting the walk, so one unreadable platform cannot strand
every other platform's orphans.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>