Performance
Making half a million files feel small
A folder with 500,000 entries took 7.7 seconds to load. An arrow key took 117 ms to paint. An idle window used more than five CPU cores to do nothing. Nine fixes later it's about 3 seconds, 11 ms and roughly zero. These are the measurements, including the ones that showed I was wrong.
Why half a million
Half a million is 500,000. I'm being literal about that because most "large folder" tests I've read stop at 10,000, and at 10,000 entries Arbora was already fine. Every interaction fit inside a frame. If I had stopped there, I could have written a short, happy post and it would have been true and also useless.
So the fixtures went up to 500,000 entries, with 1% of them subfolders. Nobody wants to open a folder like that, but people end up with them anyway: build output, photo dumps, mail spools, a node_modules that has stopped being funny. The goal wasn't "fast at 500k". The goal was that 500k shouldn't change the rules: arrow keys should still feel like arrow keys.
Some context on the stack, since it determines everything that follows. Arbora is a Rust backend with a React frontend running in the system WebView: WebKitGTK on Linux, WebView2 on Windows, WKWebView on macOS. That means every file the UI shows has to cross an IPC boundary as JSON, be decoded into a JavaScript object and then be sorted, filtered and rendered by code that shares one thread with everything else. If you've been told a WebView can't handle big lists, that's half true. This post is about which half.
How I measured
I don't trust performance claims without the conditions attached, so here are mine.
- The real app. Release backend, production frontend, WebKitGTK under Xvfb with software rendering.
- Fixtures on tmpfs. Folders of 1k, 10k, 100k and 500k entries, 1% subfolders.
- What was timed. First rows, full load, key-to-paint at p50/p95/p99, scrolling, sorting, filtering, the refresh after a file is created on disk, and the number of IPC calls. Process PSS1 and CPU were sampled throughout.
- A second harness. Chromium with a mocked backend, for CPU profiles and for listings whose batches arrive spread out over time. It's a rough stand-in for WebView2 on Windows, not a measurement of it.
- A third, smaller harness. JavaScriptCore through its GObject bindings, to time sort comparisons in isolation on the same engine WebKitGTK uses.
Every comparison is an A/B: old build and new build alternated under identical conditions, at least two rounds at 500k. That's why most results below are ranges rather than single numbers.2
The limits, before you find them yourself: software rendering inflates frame times, tmpfs hides disk latency, and none of this was run on Windows or macOS.
Where it started
| Entries | First rows | Fully loaded | Arrow key → paint (p50 / p95) | Sort click | Peak memory (WebView / backend) |
|---|---|---|---|---|---|
| 1k | 0.30 s | 0.32 s | 9 / 13 ms | 0.09 s | 481 / 86 MB |
| 10k | 0.33 s | 0.35 s | 10 / 15 ms | 0.12 s | 655 / 139 MB |
| 100k | 0.25 s | 1.26 s | 28 / 40 ms | 0.55 s | 1.4 / 0.65 GB |
| 500k | 0.30 s | 7.7 s | 117 / 169 ms | 3.7 s | 5.0 / 3.6 GB |
Some things were already right, and it would be inaccurate to leave them out. The file view only rendered the rows in view (24 to 80 elements, whatever the folder size). First rows appeared in about 0.3 s at every size. Navigating somewhere new cancelled the old listing. Arrow keys never called the backend.
So the problem wasn't one big mistake. Several smaller ones each scaled with the size of the folder, and at 500k they added up.
1. The file watcher that watched itself
This is my favourite bug of the whole pass. I know that's an odd thing to say about a bug.
On Linux, inotify doesn't only report files being created, modified or deleted. It also reports files and folders being opened, read and closed. Arbora watches the folder you're looking at, so it can refresh when something changes. To refresh, it lists the folder. Listing the folder opens it. Opening it is an event. The event triggers a refresh.
It was a closed loop: the program observing itself observing. Child counts and thumbnails each did the same thing, so there were three loops, all running in an idle window.
| Before | After | |
|---|---|---|
| Idle backend CPU, 10k folder | 100% of a core | 2.5% |
| Idle backend CPU, 100k folder | several cores | 0.3% |
| Refreshes during 300 arrow keys, 10k / 100k | 19 / 41 | 0 / 0 |
| Refreshes after creating one file, 10k / 100k | 21 / 60 | 1 / 1 |
The fix is to forward only events that can change what a listing shows. Closing a file that was open for writing counts. Every other access event doesn't:
fn changes_listing(kind: ¬ify::EventKind) -> bool {
use notify::event::{AccessKind, AccessMode, EventKind};
match kind {
EventKind::Access(AccessKind::Close(AccessMode::Write)) => true,
EventKind::Access(_) => false,
_ => true,
}
}
The debouncer Arbora uses has no event filter of its own, so this sits inside a small wrapper that implements Watcher around the platform watcher and drops events before they reach the debouncer.
Yes, the idle CPU after the fix is higher at 10k than at 100k. I don't have an explanation I trust, so I'm not giving one. Both numbers are small enough that I've stopped looking at them.
2. Re-sorting the whole folder on every batch
Listings stream in batches, so the first rows can appear before the folder has been read completely. That part worked. What happened after each batch arrived was the problem: the frontend copied the whole listing so far, filtered it, cloned it and sorted all of it. Then the next batch arrived and it did that again.
With b batches, that's b full sorts of a growing list. When batches arrive close together it's merely wasteful. When they arrive spread out, which is what you get from a slow disk or a busy remote, it's quadratic. The comparator alone accounted for about 70% of load time.
The fix has three parts:
- Precomputed sort keys. Work out each entry's key once, not once per comparison.
- A total order. When two entries compare as equal, their path breaks the tie. This matters more than it looks. Without it, merging a batch into a sorted list and sorting everything from scratch could legitimately put tied entries in different orders, and then "incremental equals full" isn't a property you can test.
- Incremental merges. Streamed batches and in-place changes are merged into the previous order instead of triggering a full re-sort. An unchanged replacement costs one linear scan.
Filters now narrow the already-sorted list instead of sorting again. Zoom and column-width changes reuse the existing order instead of invalidating it.
| Before | After | |
|---|---|---|
| Spread-out batches, 100k load (Chromium) | 8.0 s | 1.4 s |
| Spread-out batches, 500k load (Chromium) | 243 s | 33 s |
| 500k load (real app) | 7.9 s | 6.9–7.1 s |
| 500k first filter keystroke / clear filter | 2.7 / 2.3 s | 0.69 / 0.32 s |
| 500k peak memory | 4.9–5.4 GB | 4.0 GB |
To be clear about the second row: 243 seconds is the Chromium harness with deliberately delayed batches. Nobody waited four minutes for a folder in the real app on tmpfs, where the gain was about one second. The quadratic case was real, though. It just needed a slow source to show up.
3. Scanning the whole listing on every key press
Pressing an arrow key moves the cursor. Moving the cursor re-rendered the app. Re-rendering the app went through the full listing about ten times: filtering it for the selection, searching it for the cursor entry, counting hidden entries and folders, rebuilding selection sets. That's ten linear scans of 500,000 entries per key press.
None of those scans was wrong on its own, and each would pass a code review. Together, at 500k entries, they made an arrow key take a fifth of a second.
The fix:
- Selection and cursor lookups go through indexes cached per listing array, so they're only rebuilt when the listing itself changes.
- A selection that didn't change keeps its array identity, so nothing downstream thinks it changed.
- The status bar totals the selection once.
| 500k entries | Before | After |
|---|---|---|
| Arrow key (p50 / p95) | 173 / 204 ms | 53 / 63 ms |
| Page Down (p50) | 181 ms | 56 ms |
| Select all | 944 ms | 470 ms |
| Ctrl+arrow, all selected (p50 / p95) | 917 / 2390 ms | 252 / 287 ms |
53 ms is better, but it isn't good. The remaining cost turned out to be somewhere I wasn't looking yet (see fix 7).
4. Sending every entry over IPC twice
Navigation commands stream entries to the frontend over a channel, batch by batch. Then the command finishes and returns its result. The result was the whole tab, including every entry, again. At 500k entries that's roughly 100 MB of JSON per copy, decoded twice.
Now the command returns only the tab header plus the number of updates it sent. The frontend waits until the updates it has received reach that revision. Those updates can arrive after the command result, because a channel and a command reply aren't ordered with respect to each other. The adapter allows for that and fails as interrupted if updates stall. Superseded, unlisted or undelivered streams still return full entries.
| Before | After | |
|---|---|---|
| 500k load | 6.7–6.8 s | 4.9–5.0 s |
| 500k main thread blocked during load | 6.2–6.3 s | 4.3–4.4 s |
| Decoding the command result, 500k | 219–231 ms | 0 ms |
| Peak memory, 100k | 1.26–1.39 GB | 0.94–1.07 GB |
0 ms is my favourite value to put in an "after" column. It means the work isn't faster, it's gone.
5. Resending the whole listing after any change
With the watcher fixed, one file created on disk caused exactly one refresh. That refresh then returned the full listing: 500,000 entries to say that one had been added.
Now small changes return deltas, upserts and removals, against the revision the UI says it's showing. If the UI's revision isn't the one the delta was computed against, it gets the stored tab whole. A delta applied to the wrong base would be a correctness bug, and I'd rather pay for a full copy than ship one.
| One file created | Before | After |
|---|---|---|
| Refresh reply, 500k | 2.9 s | 1.3 s |
| Decoding the reply, 500k | 1.7 s | 0 ms |
| Main thread blocked afterwards, 500k | 3.2 s | 0.5 s |
| Main thread blocked afterwards, 100k | 306–352 ms | 55–62 ms |
The reply still took 1.3 seconds, because the backend was still re-reading the whole folder to work out what had changed. That's fix 9. I noticed it here and didn't get to it until the end.
6. Sorting by name was mostly collation
A 500k-entry name sort took 4.6 seconds, and about 2 of them were Intl.Collator. That's not because the collator is slow. It's because a comparison sort of 500,000 items makes on the order of ten million comparisons, and each one goes through locale-aware collation: case folding, accents, numbers compared as numbers. Doing anything ten million times is noticeable.
The idea: give each entry a plain string key whose ordinary string order approximates collation, sort those with the engine's native sort, and then repair the result with the real comparator.
The key is built like this:
- Printable ASCII is ranked by the real comparator itself. At startup, the 95 printable ASCII characters are sorted with the same comparison function the app uses, and each character gets its rank. Characters that compare as equal, like
aandA, share a rank. I like that the approximation is derived from the thing it approximates rather than from a table I typed in. - Digit runs are compared by numeric value. Shorter numbers come first, then digit by digit, and leading zeros collate as equal.
file9comes beforefile10, as people expect. - Accents are dropped through Unicode decomposition. Other scripts sort after Latin letters.
The key is only an approximation, and it's sometimes wrong: ß, ligatures, some scripts and locales. So after the native sort, entries with equal keys are ordered by the real comparator, and then one linear pass checks every adjacent pair. If they're all in order, the list is in order, because the order is transitive. If not, the pass merges the out-of-order runs:
function settle(items: Keyed[], compare: (a: Keyed, b: Keyed) => number): Keyed[] {
let runs: Keyed[][] = [];
let start = 0;
for (let i = 1; i < items.length; i++) {
if (compare(items[i - 1], items[i]) > 0) {
runs.push(items.slice(start, i));
start = i;
}
}
if (!runs.length) return items;
// A poor approximation (a locale that collates letter pairs as one, say).
if (runs.length > items.length / 8) return items.sort(compare);
runs.push(items.slice(start));
// …merge the runs pairwise until one is left
}
When the approximation is right, which is almost always, the exact comparator runs once per entry instead of about twenty times. When it's wrong, you pay some extra comparisons. The order is never wrong.
The same trick applies to sorting by type, and to sorting by size or date when the values repeat a lot (at most √n distinct values). Then most comparisons fall through to the name anyway.
| 500k entries | Before | After |
|---|---|---|
| Sort by name | 4.6–4.7 s | 2.6–2.7 s |
| Sort by type | 4.1–4.3 s | 3.2 s |
| Sort by size | 3.4 s | 2.7–2.8 s |
| Folder fully loaded | 5.4–5.6 s | 3.7–3.8 s |
At this point the sort itself took about one second per click. Total latency was still 2.6 seconds. Most of the time was going somewhere after the sort.
7. The sidebar was the biggest thing on the page
The file list was virtualized from the start. The sidebar tree wasn't, because a sidebar is small.
A sidebar is small until the folder you're in has 5,000 subfolders. The Locations tree rendered one row per subfolder, which came to about 47,000 DOM elements, and it re-rendered on every app render: every key press, every sort click.
Hiding the sidebar halved sort latency and dropped arrow keys to 8 ms. One experiment, and it pointed somewhere I wasn't looking.
The fix windows any folder with more than 200 children, rendering only the rows near the sidebar's viewport. Spacers are sized from row counts, including expanded subtrees, multiplied by the measured row height. Rows on the path to the current folder and the focused row always stay rendered, so reveal and keyboard focus keep working.
| Before | After | |
|---|---|---|
| Arrow key, 500k (p50 / p95) | 55–56 / 69–74 ms | 11 / 15–18 ms |
| Sort by name, 500k | 2.6–2.7 s | 1.1–1.2 s |
| Page elements, 500k | ~47,700 | ~3,000 |
| Peak memory, 500k | 4.1–5.6 GB | 2.6–3.1 GB |
| Arrow key, 100k (p50) | 20 ms | 10 ms |
| Sort by name, 100k | 539 ms | 272 ms |
This was the single largest improvement in the whole pass, and it was in the part of the screen I'd assumed couldn't matter. I've written that down for future me.
8. Thumbnails for tiles that were already gone
In grid view, each tile requested its thumbnail as soon as it mounted. Scroll quickly through 20,000 images and hundreds of tiles mount and unmount on the way. Each one sends a request, and most of those get cancelled again.
Now grid requests wait until the view has been still for 150 ms, and each request settles for another 150 ms before it's queued. Tiles that have scrolled away by then never reach the backend. The thumbnail for the selected file skips both delays, because you're looking at it.
| 20,000 PNGs in grid view: requests / cancellations | Before | After |
|---|---|---|
| Holding the arrow key (300 presses) | 664–685 / 488–536 | 0 / 0 |
| Fast scrolling | 420–430 / 250–264 | 5–12 / 0 |
| Random jumps | 328–359 / 266–294 | 2–20 / 0–2 |
| Thumbnails in view after scrolling stops | 48 / 48 | 48 / 48 |
I checked the last row first. A fix that sends fewer requests by showing fewer thumbnails isn't a fix. It's still 48 out of 48.
The trade-off is that during continuous scrolling, thumbnails appear after you pause rather than while you move. I think that's the right trade, but it is a trade.
9. Re-reading the whole folder to find one file
Back to the 1.3-second refresh from fix 5. Fix 5 made the reply small, but to build that reply, the backend still listed the whole folder and counted every subfolder's children.
Now the watcher records which entries of each watched folder it reported, and a watcher-driven refresh re-reads only those. It falls back to a full read when the folder itself changed, after more than 4,096 changes, when events were lost, when the listing is incomplete, or when changes couldn't be committed. Replies to Arbora's own file operations still list in full; the watcher's events for them arrive later.
| One file created | Before | After |
|---|---|---|
| Refresh reply, 500k | 1,242–1,287 ms | 2 ms |
| Refresh reply, 100k | 209–221 ms | 1 ms |
The first A/B of this change showed no gain. None. The code was right. Change tracking started in an unknown state, which meant "read everything", so the first watcher change after opening a folder still forced a full read. The benchmark creates one file. The fix was to start tracking in a known-empty state, so incremental refresh works from the first change. After that: 2 ms.
I'm including this because it's the most useful thing I learned in the whole pass. If an optimization shows no effect, measure whether it ran before concluding it doesn't work.
Where it ended
| 500k entries | Start | End |
|---|---|---|
| Folder fully loaded | 7.7 s | 2.9–3.4 s |
| Arrow key (p50 / p95) | 117 / 169 ms | 11 / 15–18 ms |
| Sort by name | 3.7–4.7 s | 1.1–1.2 s |
| A file created on disk: refresh reply | 2.9 s | 2 ms |
| Idle backend CPU | over 5 cores | ~0 |
| Peak memory, all processes | 8 GB | 2.6–3.1 GB |
| 100k entries | Start | End |
|---|---|---|
| Folder fully loaded | 1.26 s | 0.9 s |
| Arrow key (p50 / p95) | 28 / 40 ms | 10 / 14 ms |
| Sort by name | 0.55–0.72 s | 0.27 s |
At 1k and 10k entries, every interaction still fits within one frame,3 as it did before.
How I know it's still correct
Faster and wrong is worse than slow, so each change came with a check aimed at the specific way it could be wrong:
- Watcher: real Linux inotify; reading a folder never triggers a refresh.
- Incremental sorting: equal to a full sort across 16 sort settings, with removals and moves.
- Keyed sorting: path-by-path equality against an independent comparator, with deliberately awkward names and many repeated sizes.
- Selection indexes and IPC: late and stalled channel updates.
- Refresh deltas: applied only against the exact base revision.
- Thumbnails: the settle delay and holding a scroll.
- Watcher refresh: create, modify, delete and rename re-read only the reported entries, and the final listing is still complete.
- Windowed sidebar: a browser fixture with 5,000 subfolders. Top, middle and bottom positions, the last row, off-screen focus, subtree heights, deep reveal.
At the end of the pass: 273 Rust tests, 242 frontend tests and 8 IPC generator tests passed. Bindings were current, and the production build and checks passed. A browser smoke test reached the same steps before and after each change. Three of its steps fail for reasons that depend on the test environment: path-bar fitting, bookmark customization and native sidebar pinning. Those failures block the steps that come after them, so those later steps haven't been exercised. That's on the list below.
What a WebView still costs
Back to the half that's true. Every displayed entry still has to be decoded from JSON into a JavaScript object. At 500k entries, that's about 206 MB of Chromium heap after garbage collection. The WebKit web process peaks at 2 to 3 GB. An empty WebView costs about 480 MB before showing a single file. Moving sorting into a worker or across IPC would add another copy of the data, not remove one.
So: 500,000 entries went from painful to usable. A native file manager will still use less memory for the same folder, and I don't want to pretend otherwise. The architecture has a cost. The work was making sure that cost is paid once rather than ten times per key press.
What's next
- Measure Windows and macOS. Nothing above has been run there yet. On Windows, I'd start with per-row Windows Shell icon requests, which look like fix 8 waiting to happen.
- Fix the three smoke failures that depend on the environment, and exercise the steps behind them.
- The remaining 500k costs: about 1 second per column sort, and about 200 ms to apply one UI change.
If you have a folder that makes Arbora slow, I want it. Well, I want its shape: how many entries, how many folders, what kind of disk. Tell us. It goes straight onto the fixture list.
Footnotes
-
Proportional set size: shared pages are divided between the processes that share them, so adding the WebView and backend numbers doesn't count shared libraries twice. ↩
-
When two rounds produced 6.9 s and 7.1 s, the table says 6.9–7.1 s. Averaging them into 7.0 s would report a run that never happened. ↩
-
Under 16.7 ms, one frame at 60 Hz. ↩
Open a big folder
Arbora Community is free on macOS, Windows and Linux. Point it at the largest folder you have and watch the arrow keys.