Open costin-zaharia-sonarsource opened 2 years ago
In order to ensure that System.Memory is available during compilation, we add a target file with an Analyzer element, similar with:
This dependency is provided by the compiler for Roslyn 3.0.0 and newer. If your analyzer does not target Roslyn 1.x or 2.x, there is no need to include the System.Memory dependency.
If there is a need for the System.Memory dependency, it should be excluded via build customization when the current runtime is .NET Core, otherwise it can end up using slow implementations designed for compatibility with .NET Framework.
Thanks for the comment. As we currently target Roslyn 1.3.2 (Visual Studio 2015 update 3) we will have to add this dependency only when really needed.
If there is a need for the System.Memory dependency, it should be excluded via build customization when the current runtime is .NET Core, otherwise it can end up using slow implementations designed for compatibility with .NET Framework.
Do I understand correctly that it is enough to check if the target runtime is .Net Core for excluding the dependency? or the safer approach is to look at the compiler version (>=3.0.0)?
@costin-zaharia-sonarsource The performance issue is likely best mitigated by checking the target runtime.
Version Used:
MSBuild version
-17.0.0-preview-21427-02+414393fc1
System.Memory
-4.6.27617.02
Context:
At SonarSource, our
dotnet
code analyzers depend onGoogle.Protobuf
that depends onSystem.Memory
. In order to ensure thatSystem.Memory
is available during compilation, we add a target file with anAnalyzer
element, similar with:I've noticed that just by adding this reference, the total build time increased significantly:
In both cases the build time more than doubles.
I've reproduced this behavior on two separate projects:
Steps to Reproduce:
dotnet build --no-incremental /v:m /p:reportanalyzer=true /bl:akka.binlog
Directory.Build.props
with the following content:dotnet build --no-incremental /v:m /p:reportanalyzer=true /bl:akka-with-link.binlog
.\build.cmd "-restore -rebuild -c Release -subset libs -arch x64 -msbuild /bl:runtime.binlog"
.\build.cmd "-restore -rebuild -c Release -subset libs -arch x64 -msbuild /bl:runtime-with-link.binlog"
Expected Behavior: Adding a reference to a dependency should not have a significant impact on the solution build time.
Actual Behavior: The build time more than doubled.
You can find below the bin logs for akka.net. For .Net Runtime they are too big and could not be attached: akka.zip akka-system.memory-linked.binlog.zip