Skip to content

Better support for building SIMD and no-SIMD WebAssembly in the same project #78872

Open
@FranklinWhale

Description

@FranklinWhale

SIMD improves the performance of WebAssembly, but Safari and the Enhanced Security Mode of Microsoft Edge do not support it. As a result, we build 2 Wasm versions (one with SIMD and one without) in our project and utilize WebAssembly Feature Detection to load appropriate version at runtime:

const { dotnet } = await import(`./${await simd() ? "simd" : "no-simd"}/dotnet.js`);

With the following configurations in the csproj file,

<PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <Nullable>enable</Nullable>
    <RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
    <WasmMainJSPath>main.js</WasmMainJSPath>
    <OutputType>Exe</OutputType>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <WasmEnableThreads>true</WasmEnableThreads>
    <RunAOTCompilation>true</RunAOTCompilation>
    <WasmEnableExceptionHandling>true</WasmEnableExceptionHandling>
    <EnableMLUnsupportedPlatformTargetCheck>false</EnableMLUnsupportedPlatformTargetCheck>
    <InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<Choose>
    <When Condition="'$(Configuration)' != 'NoSIMD'">
        <PropertyGroup>
            <WasmEnableSIMD>true</WasmEnableSIMD>
        </PropertyGroup>
    </When>
</Choose>

The build script runs dotnet publish twice:

dotnet publish -c Release
dotnet publish -c NoSIMD --no-restore

As the project is effectively built twice, the build process takes quite some time. I hope something can be done to improve the build performance.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions