Desktop, Mobile: Fixes #10674: Fix sidebar performance regression with many nested notebooks #10676
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.
Summary
This pull request fixes a performance regression related to the time complexity of side-menu-shared/renderFolders.
In particular, f19b1c5 changed how parent folders are determined. In particular, it added an additional loop over all folders (with
.find
) when determining the parent of an item inrenderFolders
.Fixes #10674, #9889.
More detailed explanation
Based on code changes, the regression seems to have been introduced by f19b1c5, with the change in how folders' display parent ID is calculated. For example, this change added an additional loop within
folderHasChildren_
:This change caused$\mathcal{O}(n^2)$ time, where $n$ is $\mathcal{O}(n)$ .
folderHasChildren_
to be infolders.length
. Previously, it was infolderHasChildren_
is itself used in a loop over all folders:joplin/packages/lib/components/shared/side-menu-shared.ts
Lines 58 to 65 in 7e4533d
If the folder has children, it then recurses, passing the same
props
:joplin/packages/lib/components/shared/side-menu-shared.ts
Lines 66 to 69 in 7e4533d
The recursive call then iterates over all folders and uses a nested loop (with
.find
) to determine the parent ID of each:joplin/packages/lib/components/shared/side-menu-shared.ts
Lines 58 to 61 in 7e4533d
Based on this, the running time of$\mathcal{O}\big((n)(n +T(n))\big)$ (where $T(n)$ represents the recursive case) to $\mathcal{O}((n)(n^2 + T(n)))$ .
renderFoldersRecursive_
went fromTesting plan
On desktop:
This has been tested successfully on Ubuntu 24.04.
Screen recording:
folders.mp4
On mobile