Skip to content

Reduce syscalls in gomi -b restore path#123

Merged
babarot merged 3 commits intomainfrom
babarot/perf-reduce-syscalls
Apr 4, 2026
Merged

Reduce syscalls in gomi -b restore path#123
babarot merged 3 commits intomainfrom
babarot/perf-reduce-syscalls

Conversation

@babarot
Copy link
Copy Markdown
Owner

@babarot babarot commented Apr 4, 2026

WHAT

Eliminate redundant filesystem syscalls in the gomi -b restore flow by using cached file metadata, removing duplicate existence checks, and parallelizing storage listing.

WHY

Profiling showed gomi -b spent 85% of CPU time in syscalls (system 0.47s of 0.55s total CPU). Three sources of waste were identified:

  1. rejectBySize called fs.DirSize() for every file — recursively walking directories to compute sizes, even though File.Size was already populated during List() via os.Stat(). The default config sets Max: "10GB", so this ran on every invocation.

  2. Title() and Description() called os.Stat() on every render — BubbleTea re-renders visible items on each frame, causing V×2 stat calls per frame. File.IsDir from the initial List was sufficient.

  3. loadFileListCmd re-checked file existenceos.Stat() on every file, duplicating the check already done by cli.filterFiles().

  4. Storage backends listed sequentially — XDG and Legacy List() calls ran one after another instead of concurrently.

This PR also includes prior refactoring commits (design improvements from Phases 1-3).

babarot added 3 commits April 4, 2026 21:40
rejectBySize was calling fs.DirSize() for every file in trash,
recursively walking directories. Since trash.File.Size is already
populated during List() via os.Stat, use GetSize() from the
Filterable interface instead. Falls back to DirSize only when
size is unknown (0), which only happens for legacy history files.

Also adds early return when both Size.Min and Size.Max are empty.
Title() and Description() were calling os.Stat() on every render
of every visible list item. Since File.IsDir and File.Size are
already populated during List(), use those cached values instead.

Also remove the duplicate existence check in loadFileListCmd —
files are already filtered by cli.filterFiles() before reaching
the UI layer.
When multiple storage backends are configured (e.g., XDG + Legacy
in auto strategy), List() now queries them concurrently using
goroutines instead of sequentially. Results are collected via a
buffered channel.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

Code Metrics Report

main (a73fb08) #123 (97d3922) +/-
Coverage 42.2% 42.6% +0.3%
Code to Test Ratio 1:1.5 1:1.5 -0.1
Test Execution Time 3s 3s 0s
Details
  |                     | main (a73fb08) | #123 (97d3922) |  +/-  |
  |---------------------|----------------|----------------|-------|
+ | Coverage            |          42.2% |          42.6% | +0.3% |
  |   Files             |             24 |             24 |     0 |
  |   Lines             |           1835 |           1840 |    +5 |
+ |   Covered           |            776 |            784 |    +8 |
- | Code to Test Ratio  |          1:1.5 |          1:1.5 |  -0.1 |
  |   Code              |           2720 |           2739 |   +19 |
- |   Test              |           4238 |           4216 |   -22 |
  | Test Execution Time |             3s |             3s |    0s |

Code coverage of files in pull request scope (38.3% → 38.9%)

Files Coverage +/- Status
internal/trash/filter.go 50.3% +2.9% modified
internal/trash/legacy/history/history.go 42.5% -0.3% modified
internal/trash/legacy/storage.go 32.0% +0.1% affected
internal/trash/manager.go 41.7% +2.4% modified
internal/trash/storage.go 38.0% -0.7% modified
internal/trash/xdg/storage.go 32.3% -0.6% affected

Reported by octocov

@babarot babarot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, issues, etc. label Apr 4, 2026
@babarot babarot marked this pull request as ready for review April 4, 2026 15:53
@babarot babarot merged commit f6a2c41 into main Apr 4, 2026
6 checks passed
@babarot babarot deleted the babarot/perf-reduce-syscalls branch April 4, 2026 15:54
@github-actions github-actions bot mentioned this pull request Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Categorizes issue or PR as related to cleaning up code, issues, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant