Skip to content

perf(disk-usage): scan on the shared parallel engine - #276

Merged
ItsLemmy merged 8 commits into
noctalia-dev:mainfrom
iamnitesh108:perf/disk-usage-parallel
Dec 1, 2026
Merged

ItsLemmy merged 8 commits into
noctalia-dev:mainfrom
iamnitesh108:perf/disk-usage-parallel

Conversation

@iamnitesh108

@iamnitesh108 iamnitesh108 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Disk Usage now scans on several threads. It is about 5× faster, uses 36–53% less memory, and gives the same totals as before. On an SSD it also uses more threads, which makes a first scan, before the files are cached, about 1.6–2.6× faster than with one thread per core. A new Disk Usage Limit setting (Settings → Views) chooses how many items a scan covers, including No Limit. A file with several hard links now always shows its size under the same name, and the footer says when items changed during the scan.

Motivation

Large folders took several seconds to analyze, and a fixed 2 million item cap meant big system folders could never be analyzed fully. Disk Usage now uses the same multi-threaded scanner as folder sizes, so fixes to one apply to both.

Type of Change

  • New feature

Testing

Measured on a 6-core, 12-thread laptop with an NVMe SSD, using the new luciole-disk-usage-bench (-Dbenchmarks=true).

Repeat scans (files already cached). Time is the median of five runs; memory is the peak of one scan.

Tree Items Time before Time after Memory before Memory after
Source code folder 685K 1.78 s 0.33 s 97 MiB 59 MiB
Home folder snapshot 1.85M 4.5 s 0.80 s 208 MiB 133 MiB
/nix/store 2.3M 8.5 s 1.46 s 356 MiB 168 MiB

First scans (cache cleared before each run). The new scanner with one thread per core, as folder sizes use, compared with this PR's choice on SSDs. Each figure is the range of two runs.

Tree 1 thread One per core (6) This PR on an SSD (24)
Source code folder 9.4 s 2.4–3.2 s 1.6 s
Home folder snapshot 25 s 7.1–8.5 s 2.9–3.2 s
/nix/store 32 s 8.3–10.8 s 5.9–6.1 s
  • Same results: on a read-only snapshot, the total matches the old analyzer to the byte.
  • Folder sizes unaffected: luciole-folder-totals-bench gives the same times and totals as before.
  • Tests: new tests cover:
    • exact totals on a tree large enough to use several threads;
    • the same hard-link owner on every run;
    • the item limit, cancelling, and folder counts;
    • telling SSDs from spinning disks, including partitions and missing information;
    • the new setting.
  • Sanitizers: the disk usage, folder size and storage tests pass under ThreadSanitizer and AddressSanitizer. ThreadSanitizer scans of a large real folder (24 threads) and of / report nothing.
  • Checks: just lint, just format-check and just i18n-check pass.

Checklist

  • This PR is ready for review, or it is marked as Draft.
  • This change fits SCOPE.md, or its scope was agreed in an issue or on Discord first.
  • I read and followed the relevant guidance in CONTRIBUTING.md.
  • I ran just format, or this PR has no C++ changes.
  • I ran just lint and the relevant build or test commands, or explained why they were not run.
  • I ran just role-alpha-check, or this PR does not change UI colors.
  • I tested the change in a running Luciole where automated checks are insufficient.
  • I self-reviewed the changes.
  • I checked for new warnings or errors.
  • I updated docs/, or this PR does not change user-facing behavior or settings.
  • I used canonical names for settings, paths, and identifiers.

Additional Notes

Speed

  • Folders are listed on several threads once a tree passes a few thousand items. Disk Usage and folder sizes now share this scanner.
  • Each folder is opened once instead of twice, and listed into a reused buffer instead of a new one per folder.
  • When the scan ends, sorting each folder by size compares compact copies of sizes and names instead of reaching back into the whole tree.

Threads

  • Folder sizes use half the logical CPUs (one per physical core on most machines), at most 8. With files cached, more threads add CPU time without finishing sooner.
  • Disk Usage on an SSD uses two threads per logical CPU, at most 32. On a first scan most threads wait for the disk, and the extra ones keep it busy. With files cached they are slightly faster, but use 40–50% more CPU time.
  • A spinning disk, or storage Luciole can't identify (network, memory or virtual filesystems), keeps the folder-size thread count, since many threads would make a hard disk seek back and forth.

Memory

  • Each item's record takes 24 bytes, plus 20 more for a folder, down from 72 each. Details only a folder needs, such as its child list and counts, are kept in a separate folder table.
  • Names are packed into shared blocks instead of a separate string per item.
  • The tree is stored in blocks that never move, so it is never copied while it grows.
  • Memory needed only while scanning is freed as soon as the scan ends, before the result is assembled.
  • Child lists are built in place, without a temporary array the size of the tree.
  • Memory freed by the scan threads is returned to the system after each scan.

Behaviour

  • A file with several hard links is counted once, always under the same path: the first when names are compared in byte order. Before, it was counted under whichever name the scan reached first.
  • The default limit stays at 2 million items, so nothing changes unless the setting is changed.

@AdityaKr015

Copy link
Copy Markdown
Member

Damn man, 2 perf PR in a day.

@iamnitesh108
iamnitesh108 marked this pull request as ready for review December 1, 2026 13:04
@github-actions
github-actions Bot marked this pull request as draft December 1, 2026 13:05
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

The description now contains the required template structure.

@iamnitesh108
iamnitesh108 marked this pull request as ready for review December 1, 2026 13:05
@AdityaKr015 AdityaKr015 added the talia-review Ask Talia for a preliminary AI review (removed once posted) label Dec 1, 2026
@iamnitesh108
iamnitesh108 marked this pull request as draft December 1, 2026 13:17
@iamnitesh108
iamnitesh108 marked this pull request as ready for review December 1, 2026 13:56

@talia-ci talia-ci Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Talia preliminary review

Check Result
Merge score 🟢 4/5 — No issues found; likely ready after CI and human review
Findings None found
Review depth 3/5 — how thoroughly the changed code could be checked by reading it
Coverage 29 of 29 changed files reviewed

What Talia checked: Reviewed the new parallel walker, disk-usage tree/limit/hardlink accounting, storage-kind parsing, folder-totals migration, and UI/settings/doc wiring; no concrete introduced defect was supported. Remaining uncertainty is runtime concurrency behavior, which static inspection cannot fully establish.

Run details
  • Commit reviewed: 649f99c
  • Source lookups: 80 file reads, 43 searches
  • Prompt version: 859b7490ca3d

Preliminary automated review: Talia read the changed code and related source; nothing was built, run or tested, and AI can make mistakes. It is not a scope acceptance or a promise to merge; a human reviewer makes the final call. See our ethos.

@talia-ci talia-ci Bot removed the talia-review Ask Talia for a preliminary AI review (removed once posted) label Dec 1, 2026
@ItsLemmy

ItsLemmy commented Dec 1, 2026

Copy link
Copy Markdown
Member

Very nice, thx. I've added a commit that merges the two adjacent anonymous namespaces in src/fs/disk_usage.cpp.

@ItsLemmy
ItsLemmy merged commit 64e80e9 into noctalia-dev:main Dec 1, 2026
2 checks passed
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.

3 participants