Skip to content

Commit 64759a1

Browse files
committed
Improvements to performance of mono_wasm_get_assembly_exports
1 parent 5fda474 commit 64759a1

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,9 @@ private static NamespaceDeclarationSyntax GenerateRegSource(
241241
.WithModifiers(TokenList(new[] { Token(SyntaxKind.StaticKeyword) }))
242242
.WithBody(Block(registerStatements));
243243

244-
// 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
245-
// this also keeps the code protected from trimming
244+
// HACK: protect the code from trimming by putting it behind a comparison we know
245+
// will always evaluate to false at runtime, but the linker can't see through at
246+
// build time. It seems there's no attribute to block trimming of a method?
246247
MemberDeclarationSyntax initializerMethod = MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), Identifier(selfInitName))
247248
.WithAttributeLists(List(new[]{
248249
AttributeList(SingletonSeparatedList(Attribute(IdentifierName(Constants.ModuleInitializerAttributeGlobal)))),
@@ -253,8 +254,8 @@ private static NamespaceDeclarationSyntax GenerateRegSource(
253254
}))
254255
.WithBody(Block(
255256
IfStatement(BinaryExpression(SyntaxKind.EqualsExpression,
256-
IdentifierName("Environment.Version.Major"),
257-
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(7))),
257+
IdentifierName("System.Runtime.InteropServices.JavaScript.JSHost.GlobalThis"),
258+
LiteralExpression(SyntaxKind.NullLiteralExpression)),
258259
Block(SingletonList<StatementSyntax>(
259260
ExpressionStatement(InvocationExpression(IdentifierName(initializerName))))))));
260261

src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public static (string assemblyName, string nameSpace, string shortClassName, str
333333

334334
var nameSpace = "";
335335
var shortClassName = className;
336-
var idx = fqn.LastIndexOf(".");
336+
var idx = fqn.LastIndexOf('.');
337337
if (idx != -1)
338338
{
339339
nameSpace = fqn.Substring(0, idx);

0 commit comments

Comments
 (0)