1

I'm getting Heroku warnings about my slug size being too big:

-----> Compressing...
   Done: 304.9M
-----> Launching...
 !     Warning: Your slug size exceeds our soft limit (304 MB) which may affect boot time.

How can I reduce my slug size? It's a .NET Core 2.1.401 and Angular 6 app, so I'm using the following buildpacks:

Running heroku run "du . -h --max-depth=3 --threshold=1M" yields the following result:

2.5M    ./App/obj
524M    ./App/ClientApp/node_modules
16M     ./App/ClientApp/dist
9.4M    ./App/ClientApp/src
549M    ./App/ClientApp
2.5M    ./App/bin/Release
3.3M    ./App/bin
556M    ./App
16M     ./heroku_output/ClientApp/dist
16M     ./heroku_output/ClientApp
130M    ./heroku_output
189M    ./.heroku/dotnet/sdk
140M    ./.heroku/dotnet/shared
329M    ./.heroku/dotnet
27M     ./.heroku/node/lib
3.0M    ./.heroku/node/include
34M     ./.heroku/node/bin
63M     ./.heroku/node
391M    ./.heroku
11M     ./.apt/usr/lib
3.3M    ./.apt/usr/include
15M     ./.apt/usr
15M     ./.apt
1.1G    .

The bulk is in node_modules/ (524M), ./heroku/dotnet/ (329M) and ./heroku_output (130M).

I don't think I can use a .slugignore file, because the node_modules folder is required for the build process, so I tried deleting the node_modules/ folder after dotnet publish using this entry in the app's .csproj, but it didn't reduce the slug size.

<Target Name="CleanupNodeModules" AfterTargets="Publish">
  <Exec WorkingDirectory="$(SpaRoot)" Command="rm -rf node_modules" Condition=" '$(OS)' != 'Windows_NT' " ConsoleToMSBuild="true" />
</Target>

Any ideas?

dstj
  • 4,800
  • 2
  • 39
  • 61

2 Answers2

1

You might want to use IL Linker to further reduce the size of .NET Core output. Essentially it'll check for unused dependencies and remove those class libraries with unreachable code. I saw 30-50% reduction in size on self-contained .NET Core console app in macOS and Windows.

Maxim Saplin
  • 4,115
  • 38
  • 29
  • Thanks, I'll try that as well! – dstj Dec 19 '18 at 16:14
  • Besides, there's ILCompiler, it gave me 5Mb native image against ~60Mb with standard self-contained deployment. Though it didn't work for me on macOS (app crahes on startup). Might work for you though... https://stackoverflow.com/questions/44835273/is-there-a-way-to-make-a-console-application-run-using-only-a-single-file-in-ne/53743869#53743869 – Maxim Saplin Dec 20 '18 at 10:00
0

I created a pull request to build the .NET Core project as a self-contained exe and delete the .NET Core SDK afterwards.

With that, I passed from a 304MB to a 149MB slug size!

Looks like node_modules has no effect...

dstj
  • 4,800
  • 2
  • 39
  • 61