Skip to content

ALI-2598: Show a folder's item count in the Size column - #63

Merged
michaelaguiar merged 10 commits into
mainfrom
aliasbot/ali-2598-folder-counts
Dec 4, 2026
Merged

michaelaguiar merged 10 commits into
mainfrom
aliasbot/ali-2598-folder-counts

Conversation

@michaelaguiar

@michaelaguiar michaelaguiar commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Fixes ALI-2598.

A folder's Size cell was blank, so a folder full of folders showed nothing in that column. It now says how many items the folder holds, as Nautilus and Folio do.

Behaviour

  • A folder's Size reads "8 items", "1 item", "Empty" or "10,000+ items", following the show-hidden setting. A screen reader reads it as the cell's text.
  • How it's counted: one directory read per folder, capped at 10,000, on the existing listing::Stater thread after each chunk's stats. No new thread is started per folder.
  • When: only folders on screen, plus half a screen either side, are counted, and only after the rows are shown, so first paint never waits.
  • Live updates: a change in a counted folder updates its count through inotify. There are no timers; one 100 ms deadline is set only after a change, and the old count stays until the new one arrives.
    • A listing keeps live watches on at most 1,024 counted folders. Folders past that are still counted, but not kept live.
  • Not counted: network places (NFS, SMB, GVfs, sshfs and other FUSE), automount points, and symlinks into them. This is decided from the real path and the mount table, touching no disk. Local fuseblk (NTFS) is counted.
  • Sorting by size orders folders by item count, still before files.
  • The Trash, Recent and search results don't count.

Measurements

Median of 5 warm runs, headless sway, alternating with main. Idle is measured over 3 s.

Folder Build First paint All counts shown CPU PSS Idle wake-ups
steamapps/common (45) main 5.3 ms — 8.9 ms 15.0 MiB 0
branch 5.6 ms 8.9 ms 10.5 ms 15.1 MiB 0
2,000 subfolders main 6.2 ms — 9.8 ms 15.1 MiB 0
branch 5.5 ms 7.3 ms 8.8 ms 15.4 MiB 0
Holding a 20,000-entry folder main 5.3 ms — 5.9 ms 11.2 MiB 0
branch 5.6 ms 8.6 ms 10.7 ms 15.3 MiB 0

First-paint differences are under 1 ms in both directions, which is noise. The extra 4 MiB in the last row is the window's second 4 MB drawing buffer, used because the counts cause one more paint (checked in smaps). main uses it too wherever sizes arrive after first paint.

Not measured: a slow or cold drive.

Accessibility

Counts use the muted colour that file sizes use. The lowest WCAG ratio is 4.54:1 (muted on hover); on base it's 5.21:1. design/build --check passes.

Checks

  • Mike tried a dev build.
  • Unit tests pass. New ones cover counting, the cap, hidden items, links, which places are skipped, watches, sorting, the cell text and reloads.
  • Clippy: 0 warnings.
  • e2e: 120 checks pass. The new a_folders_size_says_how_many_items_it_holds covers counts, a 10,001-file folder, live updates, hidden files and sorting, and fails against main. The screen-reader check now expects "1 item".

Hardened in review (three rounds, recorded in the comments)

  • Every counted folder stays up to date: that includes folders counted for the Size sort, a change landing mid-count, and deleted or unmounted folders (their watch slot is freed). Refused watches retry only when room frees up.
  • Less work: a reload seeds counts from the last listing by (dev, ino, mtime, ctime) and only reads folders that changed. A stamp is trusted once it's at least 2 s old, for coarse-clock disks. Sorted by Size with 5,000 subfolders, a reload went from 16.1 ms to 7.1 ms (main: 4.5 ms, with no counting).
  • Backoff: a busy folder is recounted at 100 ms, doubling to at most 2 s. These timings are code constants, by the repo's convention.
  • Links: they're followed one step at a time against the mount table, and never into a network, autofs or FUSE mount. This is the same complete::avoided_fs rule path suggestions use.
  • Limits: a 100,000-entry read ceiling shows "N+ items". Transient errors are retried.
  • Layout: the rename field keeps at least 44 px beside a wide count.
  • Sort order: it follows the show-hidden setting through loads and the back cache.
  • main (ALI-2632: Hide the host's drives and network shares from the test sandboxes #62, ALI-2599: Suggest folders while a path is typed, with Tab to complete #64, ALI-2601: Format a removable drive from the sidebar #65) is merged in. Unit tests: 984. e2e: 125. CI passes.

A folder's Size cell now says how many items it holds: "8 items", "1 item",
"Empty", or "10,000+ items" past the cap, where counting stops. It follows
the show-hidden setting, and a screen reader reads it as the cell's text.

- Counting is one listing of the folder, done on the listing's stat thread
  after each chunk's stats, only for rows on screen, so first paint is
  unchanged. Counts are kept per listing in a small map, so a folder of
  files costs nothing.
- Each counted folder gets a one-shot inotify watch in a set the window
  polls. A change marks the count stale, and it's counted again 100 ms
  later; the old count shows meanwhile. Reading the folder again keeps
  the counts on screen showing until they're recounted.
- Network places aren't counted: the folder's real path and the mount
  table decide, so NFS, SMB, GVfs and other FUSE mounts (but not fuseblk),
  autofs points and links into them stay blank.
- Sorting by size counts every folder and orders folders by their count,
  still before files. Toggling hidden files re-sorts when sorted by size.
- A long count reaches left of its column, and the name beside it is cut
  short of it.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 1. The code-review skill ran, and its findings were checked against the code. Being fixed:

  • P2: folders counted for the Size sort get no watch, so they never update. Their counts will be watched, and the README wording fixed.
  • P2: a change during a count is lost, because count_one overwrites the stale mark and the one-shot watch is used up. A per-entry generation will make the count re-run.
  • P2: sorted by Size, each reload re-reads every subfolder. New listings will be seeded from the old counts. Reload cost to be measured on 5,000 subfolders.
  • P3:
    • back off on a constantly changing visible folder;
    • RECOUNT_AFTER into the tokens;
    • measure paint cost per row, and cache if needed;
    • a raw-entry ceiling for folders full of hidden files;
    • component-by-component symlink resolution, checked against the mount table, so a dead share can't hang the stat thread;
    • re-sort when Quick View shows hidden files;
    • say in the README that watches stop at the limit, and retry them;
    • check for newer requests between folder counts.
  • Declined (P3): the small layout shift when "10,000+ items" is wider than the column. It's the cap case only, and the README already notes it.

Confirmed fine:

  • watch-before-read and the generation checks;
  • IN_IGNORED, and queue overflow causing a recount;
  • shared watches;
  • the autofs, network and FUSE skip uses only /proc/self/fd and the mount table;
  • O_DIRECTORY|O_NONBLOCK;
  • unknown counts sort first;
  • the a11y text;
  • no extra thread and no idle timer.

- A folder counted for the Size sort isn't watched, so once it's on screen
  it's opened, watched, and read again only if its inode or modified time
  changed since it was counted. The same goes for a listing shown again
  from the cache, and for a folder that found no room for a watch.
- A change heard while a folder is being read marks it to count again: each
  entry keeps a mark that `recount` bumps, even before the row has a count,
  and a count that sees it moved leaves the row stale.
- Reading a folder again starts from the last listing's counts by name. The
  row's stat checks each against the folder's inode and modified time, so
  sorted by size only folders that changed are read again.
- A folder that keeps changing waits twice as long each time, up to 2 s,
  and goes back to 100 ms once it's quiet for a second. The waits are
  motion tokens: recount-after, recount-quiet and recount-max-wait.
- Counting stops after reading 100,000 entries, saying "10,000+ items".
- Links are followed a step at a time with readlink, up to 40, and each
  path on the way is checked against the mount table first, so a chain of
  links or a linked folder can't lead into a network place.
- Showing a hidden file from Quick View re-sorts when sorted by size.
- The stat thread looks for a newer request between folders it counts.
The design README keeps timings that pace work, not what's seen, in the
code, so recount-after, recount-quiet and recount-max-wait leave the token
file for named constants in app.rs, and the README lists them with the
other behaviour values.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Round 1 fixes are in 4653da6, with 0234a2b moving the timings back into code. 11 fixed, 1 declined.

  • P2, sort-counted folders weren't watched: each count records the folder's inode and mtime. A sort-counted or cached folder that comes on screen is watched, and re-read only if it changed. e2e sorts by size, adds a file to a visible folder and waits for the update; it fails on round 0.

  • P2, a change during a count was lost: a per-row change mark is bumped by recount, even for a row not yet counted, and a count that sees it move counts again. Unit test with a hook between opening and reading.

  • P2, reloads sorted by size re-read every folder: a new listing starts from the old counts by name, and a count stands if the inode and mtime match. Unit tests.

    5,000 subfolders sorted by Size, reload after one file is touched in the parent:

    Build Reload, median of 5
    main (no counting) 4.5 ms
    round 0 16.1 ms
    round 1 7.1 ms
  • P3:

    • backoff: a folder that changes again within 1 s waits twice as long, up to 2 s, and goes back to 100 ms after a quiet second. These are constants in app.rs (RECOUNT_AFTER, RECOUNT_QUIET, RECOUNT_MAX_WAIT), listed in design/README.md's behaviour values, because pacing timings stay in code by this repo's convention;
    • paint cost: measured with about 66 folder rows, main 0.92 ms and branch 0.97 ms per paint, under the 0.1 ms threshold, so no cache;
    • hidden-heavy folders: a 100,000-entry read ceiling;
    • symlinks: followed one step at a time (40 at most), each checked against the mount table, never looking inside a network, FUSE or autofs mount;
    • Quick View: turning on hidden files re-sorts when sorted by Size;
    • watches: a failed or over-limit watch is retried on a later visit;
    • the stat thread: checks for newer requests between folders.
  • Declined (P3): reserving width for "10,000+ items" would change the size-column token for every window. The README now says a cap count reaches to its left.

Unit tests: 940. Clippy: 0 warnings. design/build --check passes. e2e: 121.

@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 2. The code-review skill ran, and its findings were checked. Being fixed:

  • P2: with Size sort, the folder order depends on show-hidden, but a toggle during a load (on_loaded) and a cached folder (show_cached) reuse the old order. Both will resort.
  • P3:
    • deleted or unmounted watched folders: IN_IGNORED will free their slot;
    • failed watch adds: a per-row watch_failed, so folders aren't reopened on every scroll;
    • the read ceiling: show the visible count found so far ("N+ items");
    • coarse timestamps: a stamp is trusted only if its mtime is at least 2 s older than when it was taken, and the stamp includes st_dev;
    • links to folders: seeded too;
    • the rename field: no longer overlaps a wide count;
    • cancel: checked between folders in count_all, with timings for opening a folder already sorted by Size.

Confirmed fine:

  • the change-mark race fix;
  • watch dedup, limits and the back-list cache;
  • backoff, with no timer when idle;
  • link-following never looks inside an avoided mount;
  • no idle wakeups added.

- A sort by size goes by the items that show, so showing hidden files
  during a load sorts again, and a folder shown again from the cache sorts
  again if hidden files were shown or hidden since its order was kept.
- A watched folder deleted, or its disk unmounted, says only IGNORED: that
  frees its place and counts its row again.
- A watch the system won't add (its limit, or no /proc) isn't tried again
  on every scroll, only once a watch has been let go of, or on a new
  listing.
- A folder read only as far as the 100,000-entry ceiling says how many that
  show it found, "3+ items", and sorts by that, rather than "10,000+".
- A stamp carries the folder's disk, and is trusted only once its modified
  time is 2 s old, for disks that keep times to the second or two. A count
  without one is still shown from the last listing, and read again.
- A link to a folder whose count came from the last listing is opened to
  check its target's stamp, and read only if that changed.
- The rename field is as narrow as the name beside a wide count.
- Counting every folder for a sort checks for a cancel between folders.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Round 2 fixes are in 92fb568.

  • P2, Size order and show-hidden: the app records which show-hidden setting the order was sorted with (sorted_hidden), set by a load, a background resort and the cache. on_loaded and show_cached resort on a mismatch. Two unit tests, each failing without its fix.

  • P3, deleted or unmounted folders: IN_IGNORED frees the watch's slot and marks the row to count again. Unit test: 1,034 delete-and-recreate cycles without hitting the limit.

  • P3, refused watches: a refused watch (the limit, ENOSPC, no /proc) is retried only after Watches::freed moves, not on every scroll.

  • P3, the read ceiling: shows "N+ items" with what was seen, sorted by N, and "10,000+ items" past the cap.

  • P3, coarse timestamps: stamps include st_dev and are trusted only once the mtime is at least 2 s old (STAMP_SETTLE_SECS), tested with fixed times. With no trusted stamp, the last count shows while the folder is read again, so the cell doesn't blank.

  • P3, links to folders: a carried-over count is opened (after the network check), and only read if its stamp changed. For a link, the stamp is the target's.

  • P3, the rename field: it stops short of the count, with light and dark screenshots. The new-folder field is on its own row, so it doesn't apply.

  • P3, cancel: count_all checks for a cancel between folders. A folder already sorted by Size with 2,000 subfolders:

    Build First paint Settled and sorted
    main 13.2 ms 15.1 ms
    this branch 13.5 ms 22.5 ms

    First paint doesn't wait for the counts. The 7 ms falls inside the existing 200 ms head start a size sort gets, and anything slower shows in name order first. Showing rows first and resorting would reshuffle them on every open, so that's kept.

Unit tests: 948. Clippy: 0 warnings. design/build --check passes. e2e: 121.

@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 3 (code-review ran) on 92fb568: no P1 or P2. Confirmed:

  • sorted_hidden is set on every sorting path, with no loop and no missed resort;
  • IN_IGNORED frees only slots it owns;
  • the freed retry can't storm;
  • "N+ items" is consistent across display, a11y and sort;
  • the realtime clock matches file mtimes, and a backward jump only re-reads;
  • links are vetted before opening;
  • rename click positions are consistent.

Small cleanup coming for the P3s:

  • no "N+" when the ceiling is hit exactly;
  • a minimum rename-field width, so a narrow window can't shrink it to nothing (WCAG);
  • the watch limit is checked only for a new wd;
  • ctime in the stamp, so a set-back mtime can't fool it;
  • transient count errors (EMFILE and similar) are retried.

- "N+ items" only when an entry follows the 100,000th: a folder of exactly
  that many is counted whole.
- The rename field beside a wide count keeps at least a target's width or
  four letters, and covers the count while it's open if there's no room
  beside it. The e2e checks it at 480 px wide and twice the scale.
- The 1,024-watch limit counts only new watches, so a link to a folder
  already watched isn't refused at the limit.
- A stamp carries the folder's changed time (ctime) as well, which rsync -t,
  tar -p and touch -r can't set back, and is trusted once both times are
  2 s old.
- A count that fails for want of file descriptors, or is interrupted, keeps
  what it showed and is tried again; no permission or nothing there stays
  blank.
…der-counts

# Conflicts:
#	crates/core/src/lib.rs
… filesystems

counts::uncounted now asks complete::avoided_fs, so both avoid the same
network, autofs and FUSE (but not fuseblk) mounts, which adds sshfs and afs
to what isn't counted. The root is always counted, even as a container's
fuse-overlayfs, as the path bar's suggestions treat it.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Round 3 cleanup (d0eb52b and e431490), the merge of main (a6bee69), and one shared filesystem list (41190ab):

  • The ceiling: "N+" shows only when another entry follows the 100,000th entry. Unit test.
  • The rename field: keeps at least a 44 px target's width. With no room, it covers the count, and the count is hidden while it's open. e2e at 480 px wide and 200% asserts at least 88 physical px, with a narrow dark screenshot.
  • The watch limit: it counts only new watches, so a link to an already-watched folder isn't refused. Unit test.
  • Stamps: they include ctime, so a set-back mtime (rsync -t, tar -p) is caught. Trusted once both times are at least 2 s old. Unit test.
  • Transient errors: EMFILE, ENFILE, EAGAIN, EINTR and ENOMEM keep the shown count and retry. Others leave the cell blank.
  • Merge: main (ALI-2632: Hide the host's drives and network shares from the test sandboxes #62, ALI-2599: Suggest folders while a path is typed, with Tab to complete #64) is merged. The only conflict was lib.rs, where both modules are kept.
  • One filesystem list: counts and path suggestions disagreed: counts didn't avoid bare sshfs or afs, and refused everything on a FUSE root. counts::uncounted now uses complete::avoided_fs, so both avoid network, autofs and FUSE except fuseblk, and never /. Unit test.

Unit tests: 968. Clippy: 0 warnings. design/build --check passes. e2e: 123 of 123 on the merged tree.

…der-counts

# Conflicts:
#	crates/app/src/main.rs
@michaelaguiar
michaelaguiar marked this pull request as ready for review December 4, 2026 06:08
@michaelaguiar
michaelaguiar merged commit 4ec595d into main Dec 4, 2026
3 checks passed
@michaelaguiar
michaelaguiar deleted the aliasbot/ali-2598-folder-counts branch December 4, 2026 15:56
@michaelaguiar michaelaguiar mentioned this pull request Dec 4, 2026
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