Commit 2d1ecdf
authored
sync: stat each file once per scan, not twice (#66)
`scan_folder` called `child.metadata()` twice for every file it keeps.
`DirEntry::metadata` is a fresh `lstat` on each call, so the second one
bought nothing:
let (mtime_secs, mtime_nanos) = mtime_of(&child); // lstat
let disk = child.metadata().ok(); // lstat again
`mtime_of_metadata` already existed and takes a `&Metadata`, so the
single-call shape was in the file the whole time. `mtime_of` was a
`DirEntry` wrapper around it that forced the extra call. It has no other
caller and is removed.
MEASURED, AND IT IS A SMALL WIN. Do not read it as a large one.
The watched tree on Silber holds 17,063 files. One `lstat` pass over all
of them costs 36 ms wall on this machine, warm, best of three. The bus
entry ran 12.2 scans a minute over a 419 second window, so the redundant
call costs about 0.43 s of CPU a minute, or 0.72 percent of one core.
Treat 0.72 percent as an UPPER bound. I measured the syscall from Python,
whose per-call interpreter overhead is included in the 2.08 us per file
and would not be present in this loop.
WHAT THIS DOES NOT FIX, SO NOBODY READS IT AS THE ANSWER. The dominant
idle cost on Silber is that one changed file triggers a full walk of the
whole tree, about 21 times a minute. Halving the stats per file makes the
walk cheaper. It does not stop the walk from happening.
Agent: Silber.fabric1 parent 5ae4abd commit 2d1ecdf
1 file changed
Lines changed: 9 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1342 | 1342 | | |
1343 | 1343 | | |
1344 | 1344 | | |
1345 | | - | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
1346 | 1350 | | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
1347 | 1355 | | |
1348 | 1356 | | |
1349 | 1357 | | |
| |||
1832 | 1840 | | |
1833 | 1841 | | |
1834 | 1842 | | |
1835 | | - | |
1836 | | - | |
1837 | | - | |
1838 | | - | |
1839 | | - | |
1840 | | - | |
1841 | | - | |
1842 | 1843 | | |
1843 | 1844 | | |
1844 | 1845 | | |
| |||
0 commit comments