From 92ffa60ae76b91b1e91a9161f1d4d22bded5c45f Mon Sep 17 00:00:00 2001 From: Todd Grunke Date: Wed, 25 Jun 2025 15:21:03 -0700 Subject: [PATCH] Small but trivial allocation improvement in FileWatchedReferenceFactory.StopWatchingReference String.Concat shows up as 0.3% of allocations in cohost scrolling razor speedometer test. Just moved the concatenation closer to where it's used, as I see it not used over 95% of the time this method is called. --- .../FileWatchedPortableExecutableReferenceFactory.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Workspaces/Core/Portable/Workspace/ProjectSystem/FileWatchedPortableExecutableReferenceFactory.cs b/src/Workspaces/Core/Portable/Workspace/ProjectSystem/FileWatchedPortableExecutableReferenceFactory.cs index f68e3fa6861e..afe95e4b871b 100644 --- a/src/Workspaces/Core/Portable/Workspace/ProjectSystem/FileWatchedPortableExecutableReferenceFactory.cs +++ b/src/Workspaces/Core/Portable/Workspace/ProjectSystem/FileWatchedPortableExecutableReferenceFactory.cs @@ -142,7 +142,6 @@ public void StopWatchingReference(string fullFilePath, TReference? referenceToTr { lock (_gate) { - var disposalLocation = callerFilePath + ", line " + callerLineNumber; if (!_referenceFileWatchingTokens.TryGetValue(fullFilePath, out var watchedFileReference)) { if (referenceToTrack != null) @@ -167,6 +166,8 @@ public void StopWatchingReference(string fullFilePath, TReference? referenceToTr if (referenceToTrack != null) { + var disposalLocation = callerFilePath + ", line " + callerLineNumber; + _previousDisposalLocations.Remove(referenceToTrack); _previousDisposalLocations.Add(referenceToTrack, disposalLocation); }