Repository navigation
perf(desktop): reuse one collator for sidebar natural sort - #6039
Merged
Merged
Conversation
naturalCompare() called localeCompare() with options, which creates a new Intl.Collator on every call. Sorted inserts into the sidebar tree call it once per sibling, so opening a folder with many entries spent most of its renderer time constructing collators. A shared Intl.Collator with the same locale and options gives the same ordering.
Jocs
approved these changes
Nov 13, 2026
Jocs
left a comment
Member
There was a problem hiding this comment.
Reviewed the shared collator change. Local validation passed: 100 sidebar/project unit tests, lint, typecheck, and production builds. Verified the real Electron app on macOS with 10,001 Markdown files: natural ordering and file opening work, with lower folder loading time. This is a scoped performance improvement; it does not establish that all symptoms of #3893 are fixed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #3893
Summary
Opening a folder with many files is slow (see #3893). One reason is in the sidebar's natural sort:
naturalCompare()intreeCtrl.tscalleda.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' })for every comparison. Passing an options object makeslocaleCompareconstruct a newIntl.Collatoron every call (~6 µs each, vs ~0.3 µs for a comparison through a shared collator), and the sorted inserts inaddDirectory()/addFile()run it once per sibling for every node, so opening a large folder builds collators quadratically.This change hoists a single
Intl.Collatorwith the same (default) locale and the same options to module scope and compares through it. Per ECMA-402 the ordering is identical to the previouslocaleComparecalls, so the sort result does not change.Measurements (Windows, replaying add/addDir events into the real
treeCtrlwith a Vue reactive tree, 3 alternating rounds; renderer only, disk I/O excluded):Also verified end-to-end on Linux (Xvfb, production build, the same mdn/content clone, GUI flow from app launch until the sidebar's "Loading folder..." indicator disappears): ~36.5 s → ~28.5 s, single runs. That flow also includes app startup and the main-process directory walk (~24 s in both runs), so the renderer-side difference (~8 s) lines up with the Windows numbers.
Screen recordings (Linux, end-to-end)
Before (develop,
a520bef):marktext-before.mp4
After (this branch):
marktext-after.mp4
Type of change
Test plan
Notes for reviewers [optional]
This code was written by an AI assistant; I have read it, tested it as described above, and can answer questions about it. The change is intentionally minimal: one shared collator instead of one per comparison.
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.