perf(web): optimize shift+click range selection#28636
Open
maarteNNNN wants to merge 1 commit into
Open
Conversation
- Add O(1) hasSelectionCandidate via #candidateSet (was O(n) .some() scan per thumbnail) - Add assetId index lookup map in GalleryViewer for O(1) range slicing (was O(n) findIndex x2) - Add same-month fast path in retrieveRange() to skip async iteration
|
Label error. Requires exactly 1 of: changelog:.*. Found: 🖥️web. A maintainer will add the required label. |
Comment on lines
+90
to
+96
| let assetIndexMap = $derived.by(() => { | ||
| const map = new Map<string, number>(); | ||
| for (let i = 0; i < assets.length; i++) { | ||
| map.set(assets[i].id, i); | ||
| } | ||
| return map; | ||
| }); |
Member
There was a problem hiding this comment.
Suggested change
| let assetIndexMap = $derived.by(() => { | |
| const map = new Map<string, number>(); | |
| for (let i = 0; i < assets.length; i++) { | |
| map.set(assets[i].id, i); | |
| } | |
| return map; | |
| }); | |
| const assetIndexMap = $derived(new Map(assets.map(({ id }, i) => [id, i]))); |
| } | ||
| return range; | ||
| } | ||
|
|
Member
There was a problem hiding this comment.
Is this actually a relevant change? Is the timeline manager iterator significantly slower? Did you test it with and without this path?
| selectAssets(assets: TimelineAsset[]) { | ||
| for (const asset of assets) { | ||
| this.selectAsset(asset); | ||
| this.#selectedMap.set(asset.id, asset); |
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.
Description
I was experiencing performance issues in regard to range selecting (with Shift + Click). I presumed it was related to some reactivity stuff and wanted to optimize it. This PR cover that. Using
v2.7.5on my remote instance I frequently get freezes. My two cents is when video previews are far apart dates are in the selection mix.Basically the PR introduces a hashmap for faster lookups and improving the selection performance.
Fixes # (issue)
How Has This Been Tested?
I initially tried against my remote instance since the data was there. But since there are too many breaking changes in
mainat the moment I needed to copy my data of my remote instance locally. I initially tried the performance enhancements basing myself ofv2.7.5using my remote machine for ease to confirm that I could fix it and it proved to be way smoother.After confirming I backed up my remote DB and photos and setup my local setup with the same data and added my performance enhancements again.
Checklist:
src/services/uses repositories implementations for database calls, filesystem operations, etc.src/repositories/is pretty basic/simple and does not have any immich specific logic (that belongs insrc/services/)Please describe to which degree, if any, an LLM was used in creating this pull request.
I've used an LLM to find the relevant pieces of code to adapt, setup and debug the breaking
mainbranch with copying over my remotev2.7.5db and it generated the commit message.