Skip to content

perf(mediascanner): use fastwalk for parallel directory walking#550

Merged
wizzomafizzo merged 3 commits intomainfrom
perf/fastwalk-mediascanner
Mar 6, 2026
Merged

perf(mediascanner): use fastwalk for parallel directory walking#550
wizzomafizzo merged 3 commits intomainfrom
perf/fastwalk-mediascanner

Conversation

@wizzomafizzo
Copy link
Member

Summary

  • Replace filepath.WalkDir with charlievieth/fastwalk for parallel directory traversal in GetFiles(). fastwalk walks subdirectories concurrently, skips per-directory sorting, and uses raw syscalls to reduce overhead. Built-in symlink following with cycle detection replaces the manual visited map and recursive walk logic, cutting GetFiles() from ~180 lines to ~50.
  • Remove dirCache (dircache.go) which cached root directory listings during path discovery. The kernel page cache already makes repeat ReadDir calls essentially free, so the userspace cache was redundant. GetSystemPaths now uses FindPath uniformly for all folder lookups — simpler and still timeout-protected via fsutil.go for stale NAS/mount handling.
  • Increase zaplink HTTP client timeouts to more reasonable values for real-world network conditions.

Benchmarked on MiSTer (single available core): ~5% improvement on walk phase. Multi-core platforms should see larger gains from the parallel workers.

Replace filepath.WalkDir with charlievieth/fastwalk for parallel
directory traversal in GetFiles(). fastwalk walks subdirectories
concurrently, skips per-directory sorting, and uses raw syscalls to
reduce overhead. Also enables built-in symlink following with cycle
detection, replacing the manual visited map and recursive walk logic.

Remove dirCache (dircache.go) which cached root directory listings
during path discovery. The kernel page cache already makes repeat
ReadDir calls on the same directory essentially free, making the
userspace cache redundant. GetSystemPaths now uses FindPath uniformly
for all folder lookups, which is simpler and still timeout-protected
via fsutil.go wrappers for stale mount handling.
Raise dial, TLS handshake, response header, and overall client timeouts
to more reasonable values for real-world network conditions.
@sentry
Copy link

sentry bot commented Mar 5, 2026

Codecov Report

❌ Patch coverage is 64.81481% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/database/mediascanner/mediascanner.go 64.81% 14 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

Add tests for relative folder resolution in GetSystemPaths, nonexistent
folder skipping, and ZipsAsDirs handling in the fastwalk-based GetFiles.
@wizzomafizzo wizzomafizzo merged commit a00408f into main Mar 6, 2026
10 checks passed
@wizzomafizzo wizzomafizzo deleted the perf/fastwalk-mediascanner branch March 6, 2026 09:28
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