Skip to content

Commit

Permalink
Improvements to performance of mono_wasm_get_assembly_exports
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Apr 3, 2024
1 parent 89bd910 commit 96666c5
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ private static NamespaceDeclarationSyntax GenerateRegSource(
.WithModifiers(TokenList(new[] { Token(SyntaxKind.StaticKeyword) }))
.WithBody(Block(registerStatements));

// when we are running code generated by .NET8 on .NET7 runtime we need to auto initialize the assembly, because .NET7 doesn't call the registration from JS
// this also keeps the code protected from trimming
// HACK: protect the code from trimming by putting it behind a comparison we know
// will always evaluate to false at runtime, but the linker can't see through at
// build time. It seems there's no attribute to block trimming of a method?
MemberDeclarationSyntax initializerMethod = MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), Identifier(selfInitName))
.WithAttributeLists(List(new[]{
AttributeList(SingletonSeparatedList(Attribute(IdentifierName(Constants.ModuleInitializerAttributeGlobal)))),
Expand All @@ -253,8 +254,8 @@ private static NamespaceDeclarationSyntax GenerateRegSource(
}))
.WithBody(Block(
IfStatement(BinaryExpression(SyntaxKind.EqualsExpression,
IdentifierName("Environment.Version.Major"),
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(7))),
IdentifierName("System.Runtime.InteropServices.JavaScript.JSHost.GlobalThis"),
LiteralExpression(SyntaxKind.NullLiteralExpression)),
Block(SingletonList<StatementSyntax>(
ExpressionStatement(InvocationExpression(IdentifierName(initializerName))))))));

Expand Down

0 comments on commit 96666c5

Please sign in to comment.