Skip to content

find: look up whether each owner and group exists once for -nouser and -nogroup - #1043

Merged
sylvestre merged 1 commit into
uutils:mainfrom
KrushnXGIT:find-cache-nouser
Nov 24, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
KrushnXGIT:find-cache-nouser

Conversation

@KrushnXGIT

Copy link
Copy Markdown
Contributor

-nouser and -nogroup looked up the passwd or group entry of every file, which reads /etc/passwd or /etc/group again each time: on a 37,256-entry tree, -nouser -o -nogroup opened them 37,256 and 37,079 times.

This remembers per id whether it has an entry, next to the name cache from #1033. A failed lookup still counts as no entry, as before, but is not remembered, so every file gets the answer the per-file lookup gave.

37,256 entries on tmpfs, hyperfine, 15 runs:

-nouser -nouser -o -nogroup passwd + group opens
GNU 4.9 145.8 ± 1.1 ms 230.6 ± 5.9 ms 37,055 + 37,457
main 156.2 ± 0.7 ms 242.1 ± 1.5 ms 37,256 + 37,079
this PR 52.8 ± 0.3 ms 54.4 ± 0.6 ms 3 + 4

Output and exit codes match main for -nouser, -nogroup, -nouser -o -nogroup, ! -nouser, -nouser -nogroup, -nouser -ls, -nogroup -printf and -print0, on a tree with owners that have no entry, nobody and nogroup. They match GNU 4.9 and 4.10 too, apart from -nouser -ls, where main already differs from GNU.

With #1033, every per-file user and group lookup in find now goes through this cache, which finishes the last item of #430.

Closes #430

@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.74468% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.39%. Comparing base (3d12105) to head (1d07d5b).

Files with missing lines Patch % Lines
src/find/matchers/names.rs 95.55% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1043      +/-   ##
==========================================
+ Coverage   92.29%   92.39%   +0.09%     
==========================================
  Files          38       38              
  Lines        8714     8745      +31     
  Branches      429      427       -2     
==========================================
+ Hits         8043     8080      +37     
+ Misses        532      529       -3     
+ Partials      139      136       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Nov 24, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 15 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 20 untouched benchmarks


Comparing KrushnXGIT:find-cache-nouser (1d07d5b) with main (3d12105)

Open in CodSpeed

})
}

fn exists(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a second cache per id next to cached. could one map with Option<String> cover both, or is it not worth it?

@sylvestre
sylvestre merged commit 1140994 into uutils:main Nov 24, 2026
35 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

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.

Create cache to optimize.

2 participants