-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update the WeakStringCache to keep strong references to smaller strings. #11271
base: main
Are you sure you want to change the base?
Conversation
Hello and thank you for looking into possible performance improvements. |
Related to #11160 |
I have lots of various data including traces with PerfView and build times. If you're looking for something specific, I likely have it :). The value was chosen somewhat arbitrability, but I did see a good number of strings that were significantly larger (1000+). There's likely some tuning we could do on the specific value. |
Experimental VS insertion: https://devdiv.visualstudio.com/DevDiv/_git/VS/pullrequest/603315?_a=overview |
I've updated the WeakStringCache_Tests since these were testing the cache forgetting behavior on old strings. |
I've done some basic local benchmarking of the cache.
As a note, I'm still uncertain how to handle the spikes and what to consider a spike. For now I've removed all 40s+ values from the measurement for -core and 42s+ from the framework. I'm aware this isn't perfect so take this just as an initial estimate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I like it, with some caveats.
- so far my benchmarking was inconclusive. I will have to benchmark more.
- isn't this a potential memory leak for a long-running VS sessions? (e.g. if we introduce permanent cache and some build repeatedly generates random sub-500 character strings)
More benchmarking. On a devbox it definitely helps |
One question that came to my mind:
I'm unsure about the severity of this - there is definitely a room for maneouvering and trade offs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is ok, I agree it does what it claims to do.
I am concerned about the strategy with @SimaTian 's analysis.
It would speed up the average build (empirically and from theory), but in the persistent scenario (VS, core MSBuild server) the "memory leak" is bad. Customers would be quite sad when their long running VS consumed gigabytes of RAM on ever-growing MSBuild cache. The strong references would have to be purged at some time/capped.
Fixes #
Context
The current string cache implementation uses weak GC handles to avoid holding onto references to strings for longer than needed. As a result, the strings are frequently collected and recreated. Additionally, weak references add additional cost to each garbage collection. The proposed implementation would keep only use a weak reference for larger strings since the cost of keeping around smaller strings generally outweighs the cost of recreating them.
Changes Made
Testing
Notes