Skip to content

[Feature Request] Reduce output binary size of project build results #2736

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

Open
filzrev opened this issue May 24, 2025 · 1 comment · May be fixed by #2737
Open

[Feature Request] Reduce output binary size of project build results #2736

filzrev opened this issue May 24, 2025 · 1 comment · May be fixed by #2737

Comments

@filzrev
Copy link
Contributor

filzrev commented May 24, 2025

When building BenchmarkDotNet project.
bin directory takes about 79MB, and runtimes directory takes about 47MB of them.
These files are also outputted for build results of CsProjToolChain.

Is it able to remove these files?


These runtimes files are almost copied from Gee.External.Capstone package.
And these files seems required when using DisassemblyDiagnoser and requires only benchmark target runtime.

Image

I thought it's better to copy runtime that are required for current build environment by default.
Playwright.NET using this approach. https://playwright.dev/dotnet/docs/library#bundle-drivers-for-different-platforms

Example custom MSBuild target
I've confirmed. It can remove runtimes files by using following custom target.
(Note: It's tested Windows Environment only)

  <PropertyGroup>
    <!-- When TargetFramework containstarget platform -->
    <BenchmarkDotNetTargetPlatform Condition="'$(BenchmarkDotNetTargetPlatform )' == ''">%(RuntimePack.RuntimeIdentifier)</BenchmarkDotNetTargetPlatform >
    <BenchmarkDotNetTargetPlatform Condition="'$(BenchmarkDotNetTargetPlatform )' == ''">$(RuntimeIdentifier)</BenchmarkDotNetTargetPlatform >
    <BenchmarkDotNetTargetPlatform Condition="'$(BenchmarkDotNetTargetPlatform )' == ''">$(RuntimeIdentifiers)</BenchmarkDotNetTargetPlatform >

    <!-- Otherwise, resolve current build platform -->
    <BenchmarkDotNetTargetPlatform Condition="'$(BenchmarkDotNetTargetPlatform)' == '' AND $([MSBuild]::IsOSPlatform('Linux'))   AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X86'">linux-X86</BenchmarkDotNetTargetPlatform>
    <BenchmarkDotNetTargetPlatform Condition="'$(BenchmarkDotNetTargetPlatform)' == '' AND $([MSBuild]::IsOSPlatform('Linux'))   AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64'">linux-x64</BenchmarkDotNetTargetPlatform>
    <BenchmarkDotNetTargetPlatform Condition="'$(BenchmarkDotNetTargetPlatform)' == '' AND $([MSBuild]::IsOSPlatform('Linux'))   AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">linux-arm64</BenchmarkDotNetTargetPlatform>
    <BenchmarkDotNetTargetPlatform Condition="'$(BenchmarkDotNetTargetPlatform)' == '' AND $([MSBuild]::IsOSPlatform('Windows')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X86'">win-x86</BenchmarkDotNetTargetPlatform>
    <BenchmarkDotNetTargetPlatform Condition="'$(BenchmarkDotNetTargetPlatform)' == '' AND $([MSBuild]::IsOSPlatform('Windows')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64'">win-x64</BenchmarkDotNetTargetPlatform>
    <BenchmarkDotNetTargetPlatform Condition="'$(BenchmarkDotNetTargetPlatform)' == '' AND $([MSBuild]::IsOSPlatform('Windows')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">win-arm64</BenchmarkDotNetTargetPlatform>
    <BenchmarkDotNetTargetPlatform Condition="'$(BenchmarkDotNetTargetPlatform)' == '' AND $([MSBuild]::IsOSPlatform('OSX'))     AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64'">osx-x64</BenchmarkDotNetTargetPlatform>
    <BenchmarkDotNetTargetPlatform Condition="'$(BenchmarkDotNetTargetPlatform)' == '' AND $([MSBuild]::IsOSPlatform('OSX'))     AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">osx-arm64</BenchmarkDotNetTargetPlatform>
  </PropertyGroup>

  <Target Name="FilterCopyLocalFiles" AfterTargets="ResolveLockFileCopyLocalFiles">
    <ItemGroup Condition="'$(BenchmarkDotNetTargetPlatform)' != '' AND $(BenchmarkDotNetTargetPlatform) != 'all'">
      <ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)"
                               Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'Gee.External.Capstone'  AND '%(ReferenceCopyLocalPaths.RuntimeIdentifier)' != $(BenchmarkDotNetTargetPlatform)" />
    </ItemGroup>
  </Target>

Additionally Microsoft.CodeAnalysis satellite assemblies takes about 6MB.
These files should be removed also if possible. (via SatelliteResourceLanguages property or custom MSBuild target)

@timcassell
Copy link
Collaborator

If you push your changes to a branch on your fork, it should automatically run the tests on Linux and windows so you can see if it works properly. Happy to review a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants