.netasp.net-core.net-coreasp.net-core-2.2

What are differences between Portable and win-x64 when deploying?


I deploy my code to IIS on Windows Server 2016 and I am trying to understand the effective difference between selecting Portable vs win-x64 in the Publish/Settings/Target Runtime dropdown.

Will the site take longer to start under Portable because the JIT needs to compile the code to the specific architecture? Is there anything else?

enter image description here


Solution

  • Edit - Short Answer

    If you choose portable, every time the app starts up it will need to go through JIT compilation on the parts of the application that actually execute. If your application is large, the performance can be impacted.

    If you choose x64, the application will not slow down from compilation, because that is already done by the publish process on the build machine (your laptop).


    Original Answer

    When you choose the Portable publish option, you'll get a package that is capable of running on either x86 (32-bit) machines and x64 (64-bit) machines. With the portable option selected, on application launch you'll get JIT compiled code for the target machine (either x64 or x86) as the application stays running. However, if the application closes, all the code that was JIT compiled would be lost. The compiled code sits in memory until the application process ends. The next run would have to JIT compile the application again as it is used. The advantage here is that you'd only need to distribute one package, and it'll run on both x86/x64 machines.

    The alternative is generating multiple packages, one for each target platform you intend to distribute your application on though. In this case, you'll get machine-specific packages that are already compiled, and do not require recompilation even after the application process ends and is restarted later. In this case your application will appear to run faster since the compilation is done once and only once, on the build server / machine. However it does impact your deployment style.

    More information on .NET runtime identifiers can be found here: https://learn.microsoft.com/en-us/dotnet/core/rid-catalog

    And a good document on JIT compiled code is here: https://www.telerik.com/blogs/understanding-net-just-in-time-compilation