Improve performance of UriIdentityService (#273108)#273111
Improve performance of UriIdentityService (#273108)#273111jrieken merged 10 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR improves the performance of the UriIdentityService by optimizing its internal caching mechanism. The changes reduce object creation overhead and improve cache cleanup efficiency.
Key changes:
- Migrated from SkipList to native Map with string keys to reduce URI object creation
- Refactored path casing logic into a separate PathCasingCache class
- Replaced full-sort cache cleanup with quickSelect algorithm to find median value
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/vs/platform/uriIdentity/common/uriIdentityService.ts | Refactored UriIdentityService to use Map with string keys, extracted PathCasingCache class, and optimized cache cleanup with quickSelect |
| src/vs/platform/uriIdentity/test/common/uriIdentityService.test.ts | Added test to verify cache eviction respects access time when cache overflows |
src/vs/platform/uriIdentity/test/common/uriIdentityService.test.ts
Outdated
Show resolved
Hide resolved
42f61f3 to
528a459
Compare
528a459 to
01f4c01
Compare
jrieken
left a comment
There was a problem hiding this comment.
Can we leave cosmetic changes (formatting, extracting code) out of this PR. It makes reviewer harder and only serves personal preferences. Thanks
| scheme: string; | ||
| } | ||
|
|
||
| class PathCasingCache extends Disposable { |
There was a problem hiding this comment.
Extracting PathCasingCache is just cosmetic and to your personal preference or am I missing some "real" change here?
There was a problem hiding this comment.
Hi Johannes. Thanks for the thoughtful review!
This is mixture of cosmetic and real change. Let me try to clarify this and the next comment.
The current behavior works in the following way:
- We create a
new ExtUri(ignorePathCasing)passing thereignorePathCasingcallback as a parameter - On the
UriIdentityServiceside we maintain a map that keeps track of case sensitivity for each file system - Since SkipList uses
this.extUrifor each comparison it automatically uses the latest version of case-sensitivity state
However with the new pre-generated string keys situation is different:
- We generate keys on insertion using the current state of case-sensitivity
- On read we do NOT read the state of case-sensitivity, so we can read wrong URI if case-sensitivity for a certain file system has changed
- To fix this, there are two options: regenerate keys or simply clean them up from cache and let them to be regenerated on the next read
- Since in comparison to just updating boolean (what happens today), both of that options is relatively expensive we don't want to do that on each
onDidChangeFileSystemProviderCapabilitiesevent, since it may be related to some other capability. So we only do that when case sensitivity changes. - Overall this logic became slightly more complicated. Today: update boolean on every event. Now: maintain case-sensitivity state and clean up the main cache if it changes. So I decided that it would make sense to extract all case-sensitivity tracking logic into a separate class to keep each class focused on they primary purpose. Case sensitivity cache - track case sensitivity state and inform the main class when it changes. The main class maintain URI cache and (partially) clear it when needed.
Does this split make sense from your perspective?
| if (entry.uri.scheme !== e.scheme) { | ||
| continue; | ||
| } | ||
| this._canonicalUris.delete(key); |
There was a problem hiding this comment.
This is new behaviour, right? So when the FS casing has changes old canonical uris are dropped
There was a problem hiding this comment.
See response here. I tried to cover both comments in a single response.
I reverted every change possible to minimize diff. |
6e5b4c6 to
781f319
Compare
Thanks for doing that and for this high quality PR. It's the details that make a great product. You can pick up a thank you here: https://swag.code.visualstudio.com |
This CL improves perfrormance of UriIdentityService:
quickSelectto pick median value instead of sorting the entire cache.Changes measured on my local machine (MacBook Air M4):
153ms->18ms297ms->81ms297ms->17msFixes #273108