-
Notifications
You must be signed in to change notification settings - Fork 87
Fix static member exports to not instantiate declaring type #594
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: AArnott <[email protected]>
Co-authored-by: AArnott <[email protected]>
Co-authored-by: AArnott <[email protected]>
nuget.config
Outdated
@@ -5,7 +5,7 @@ | |||
</config> | |||
<packageSources> | |||
<clear /> | |||
<add key="msft_consumption_public" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/msft_consumption_public/nuget/v3/index.json" /> | |||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> |
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.
Revert this.
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.
Reverted in commit c4ecf24
test/Microsoft.VisualStudio.Composition.Tests/StaticMemberExportsTests.cs
Outdated
Show resolved
Hide resolved
…er tests Co-authored-by: AArnott <[email protected]>
@@ -262,7 +268,7 @@ public void StaticPropertyExportDoesNotInstantiateClass(IContainer container) | |||
Assert.False(ClassWithStaticMemberExports.ConstructorCalled, "Constructor should not be called for static property export"); | |||
} | |||
|
|||
[MefFact(CompositionEngines.V3EmulatingV1, typeof(ClassWithStaticMemberExports))] | |||
[MefFact(CompositionEngines.V1Compat | CompositionEngines.V2Compat | CompositionEngines.V3EmulatingV1 | CompositionEngines.V3EmulatingV2, typeof(ClassWithStaticMemberExports))] |
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.
V1Compat includes V3EmulatingV1, and V2Compat includes V3EmulatingV2.
Please drop the redundant flags.
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.
Removed redundant flags V3EmulatingV1 and V3EmulatingV2 from test attributes. Tests now use only V1Compat and V2Compat as requested (commit 4648648).
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: AArnott <[email protected]>
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
test/Microsoft.VisualStudio.Composition.Tests/StaticMemberExportsTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.VisualStudio.Composition.Tests/StaticMemberExportsTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.VisualStudio.Composition.Tests/StaticMemberExportsTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: AArnott <[email protected]>
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Problem
When accessing static member exports through MEF, the framework was unnecessarily instantiating the declaring type, even though static members don't require an instance. This caused performance overhead and potential unwanted side effects from constructor execution.
Consider this example:
Before this fix, MEF would instantiate the
Some
class when obtaining the value of the staticMember
property, even though instantiation is not necessary for static members.Root Cause
The issue occurred in two places:
ExportProvider.CreateExport()
- Always calledGetValueReadyToRetrieveExportingMembers()
even for static members, causing instantiationRuntimeExportProvider.GetExportedValue()
- Always createdpartLifecycle
even for static members, which could trigger instantiationSolution
ExportProvider.CreateExport()
andRuntimeExportProvider.GetExportedValue()
to check if members are static usingMemberRef.IsStatic()
before creating part lifecycle trackersGetValueFromMember(null, ...)
directlyTests Added
StaticFieldExportDoesNotInstantiateClass
- Verifies static fields don't cause instantiationStaticPropertyExportDoesNotInstantiateClass
- Verifies static properties don't cause instantiationStaticMethodExportDoesNotInstantiateClass
- Verifies static methods don't cause instantiationStaticExportInMixedClassDoesNotInstantiateClass
- Verifies static exports in mixed classes don't cause instantiationInstanceExportInMixedClassDoesInstantiateClass
- Verifies instance exports still work correctlyThe fix ensures static member exports perform better and don't have unwanted side effects from unnecessary instantiation, while maintaining full compatibility with existing functionality.
Fixes #593.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
1elvsblobprodwus2177.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)dotnet build src/Microsoft.VisualStudio.Composition/Microsoft.VisualStudio.Composition.csproj
(dns block)1mcvsblobprodwus2174.vsblob.vsassets.io
dotnet build
(dns block)1n8vsblobprodwus2184.vsblob.vsassets.io
dotnet build src/Microsoft.VisualStudio.Composition/Microsoft.VisualStudio.Composition.csproj
(dns block)2wrvsblobprodwus2180.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)5o1vsblobprodwus2115.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)5zivsblobprodwus217.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)dotnet build src/Microsoft.VisualStudio.Composition/Microsoft.VisualStudio.Composition.csproj
(dns block)78kvsblobprodwus2152.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)7q7vsblobprodwus2144.vsblob.vsassets.io
dotnet build
(dns block)dotnet build src/Microsoft.VisualStudio.Composition/Microsoft.VisualStudio.Composition.csproj
(dns block)7t8vsblobprodwus2168.vsblob.vsassets.io
dotnet build
(dns block)84hvsblobprodwus2148.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)8wdvsblobprodwus2137.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)8yfvsblobprodwus2171.vsblob.vsassets.io
dotnet build src/Microsoft.VisualStudio.Composition/Microsoft.VisualStudio.Composition.csproj
(dns block)an0vsblobprodwus2146.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)b15vsblobprodwus2164.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)b5svsblobprodwus2116.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)balvsblobprodwus2129.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)cbvvsblobprodwus2131.vsblob.vsassets.io
dotnet build --force
(dns block)etjvsblobprodwus2172.vsblob.vsassets.io
dotnet build src/Microsoft.VisualStudio.Composition/Microsoft.VisualStudio.Composition.csproj
(dns block)g3xvsblobprodwus2151.vsblob.vsassets.io
dotnet build
(dns block)hd3vsblobprodwus2117.vsblob.vsassets.io
dotnet build src/Microsoft.VisualStudio.Composition/Microsoft.VisualStudio.Composition.csproj
(dns block)i01vsblobprodwus216.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)dotnet build src/Microsoft.VisualStudio.Composition/Microsoft.VisualStudio.Composition.csproj
(dns block)ia4vsblobprodwus2112.vsblob.vsassets.io
dotnet build src/Microsoft.VisualStudio.Composition/Microsoft.VisualStudio.Composition.csproj
(dns block)izzvsblobprodwus2142.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)jhgvsblobprodwus2167.vsblob.vsassets.io
dotnet build
(dns block)jk4vsblobprodwus2186.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)/home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js
(dns block)jlovsblobprodwus2163.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)jqivsblobprodwus2187.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)mdcvsblobprodwus2159.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)mt2vsblobprodwus2110.vsblob.vsassets.io
dotnet build src/Microsoft.VisualStudio.Composition/Microsoft.VisualStudio.Composition.csproj
(dns block)ndavsblobprodwus219.vsblob.vsassets.io
dotnet build
(dns block)nypvsblobprodwus2178.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)p2tvsblobprodwus2189.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)s0ivsblobprodwus2134.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)dotnet build src/Microsoft.VisualStudio.Composition/Microsoft.VisualStudio.Composition.csproj
(dns block)tn2vsblobprodwus2124.vsblob.vsassets.io
dotnet build
(dns block)dotnet build src/Microsoft.VisualStudio.Composition/Microsoft.VisualStudio.Composition.csproj
(dns block)v41vsblobprodwus2175.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)vd2vsblobprodwus2150.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)wlnvsblobprodwus2188.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)wztvsblobprodwus2155.vsblob.vsassets.io
dotnet build src/Microsoft.VisualStudio.Composition/Microsoft.VisualStudio.Composition.csproj
(dns block)x1mvsblobprodwus2181.vsblob.vsassets.io
dotnet build
(dns block)xktvsblobprodwus2141.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)dotnet build src/Microsoft.VisualStudio.Composition/Microsoft.VisualStudio.Composition.csproj
(dns block)xofvsblobprodwus2114.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)y1mvsblobprodwus2138.vsblob.vsassets.io
dotnet build
(dns block)dotnet build --force
(dns block)dotnet build src/Microsoft.VisualStudio.Composition/Microsoft.VisualStudio.Composition.csproj
(dns block)zugvsblobprodwus2169.vsblob.vsassets.io
dotnet build src/Microsoft.VisualStudio.Composition/Microsoft.VisualStudio.Composition.csproj
(dns block)If you need me to access, download, or install something from one of these locations, you can either: