Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default new runtime feature switches #23932

Merged
2 commits merged into from
Jul 16, 2020
Merged

Default new runtime feature switches #23932

2 commits merged into from
Jul 16, 2020

Conversation

eerhardt
Copy link
Member

These new feature switches have been added to the runtime to make applications smaller. Setting reasonable defaults to Blazor wasm projects.

Fix #23716

See related SDK change to add the last 2 properties: dotnet/sdk#12457

These new feature switches have been added to the runtime to make applications smaller. Setting reasonable defaults to Blazor wasm projects.

Fix dotnet#23716
@ghost ghost added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jul 14, 2020
@@ -25,6 +25,14 @@ Copyright (c) .NET Foundation. All rights reserved.
<!-- Trimmer defaults -->
<PublishTrimmed Condition="'$(PublishTrimmed)' == ''">true</PublishTrimmed>
<TrimMode Condition="'$(TrimMode)' == ''">link</TrimMode>
<TrimmerRemoveSymbols Condition="'$(TrimmerRemoveSymbols)' == ''">false</TrimmerRemoveSymbols>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SDK defaults TrimmerRemoveSymbols based on DebuggerSupport. If DebuggerSupport is false, then the linker will remove the symbols. Since the Blazor SDK removes symbols from the publish output, I thought it was reasonable to always default TrimmerRemoveSymbols=false so even if DebuggerSupport is false in Release mode, we still get the linked symbols, in case the developer wants to archive the linked symbols.

cc @sbomer @vitek-karas

Copy link
Member

@sbomer sbomer Jul 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me - I doubt that processing symbols significantly changes link time. Curious that the logic to remove symbols from publish isn't shared.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the trimmer already has support for removing symbols, it might be useful to just piggy back on it. Would it help if we removed BlazorWebAssemblyEnableDebugging and defaulted DebuggerSupport to false?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it help if we removed BlazorWebAssemblyEnableDebugging

I think this makes sense - might as well use the established properties in the core SDK and the runtime.

and defaulted DebuggerSupport to false?

Is there ever a case where you'd want to preserve .pdbs for later debugging or perf sampling? I guess if users wanted symbols (but wanted to trim out the debug-only code for smaller apps) they could just set TrimmerRemoveSymbols themselves. I guess the current default behavior in Blazor WASM is to not get symbols. So I think that would be fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I agree, only one concern:

  • People will probably not realize that the build doesn't produce PDBs at the beginning
  • They will only find out once they actually need the PDB for anything... but then it's too late as the deployed builds of the app won't have it
  • Making it opt-in solves the problem only partially (for those who can redeploy and repro the issue)

I guess it depends on how we think people we use the PDBs for Blazor (and if they bring any value).

For example for server .NET Core apps (ASP.NET) I personally would definitely vote for always producing PDBs and just not bundling them to the final package.

Copy link
Member Author

@eerhardt eerhardt Jul 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it depends on how we think people we use the PDBs for Blazor (and if they bring any value).

One place this brings value is when we start producing linker warnings. If the pdb is available, the linker will give source and line info in the warning. The developer will see the exact line of code causing the warning. That's super useful IMO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking is that having the .pdbs available somewhere - e.g. in the obj folder - by default, even if they are removed from the published assets, is useful. Honestly, I'm not sure why dotnet publish puts symbols in the publish folder by default.

https://github.com/dotnet/sdk/blob/44e5d1aa5ee51726096156f9c0d49e3b90c33f01/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets#L484

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking is that having the .pdbs available somewhere - e.g. in the obj folder - by default, even if they are removed from the published assets, is useful.

Those should still be around. We don't prevent creating the pdbs, just stop it from being copied to the publish output.

If the pdb is available, the linker will give source and line info in the warning

Couldn't the linker still use pdbs and then discard these?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't the linker still use pdbs and then discard these?

If TrimmerRemoveSymbols is set to true, the linker won't update the symbols for the linked assemblies. Having the pre-trimmed symbols won't do you any good if you are using the trimmed assemblies - they won't match.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re source line info from linker: For this the linker needs the pdbs on the input - it doesn't matter if the linker itself will not write a pdb for this feature. That said I agree that having the pdbs (after linking) around somewhere is a good thing.

<UseSystemResourceKeys Condition="'$(UseSystemResourceKeys)' == ''">true</UseSystemResourceKeys>
<EnableUnsafeUTF7Encoding Condition="'$(EnableUnsafeUTF7Encoding)' == ''">false</EnableUnsafeUTF7Encoding>
<HttpActivityPropagationSupport Condition="'$(HttpActivityPropagationSupport)' == ''">false</HttpActivityPropagationSupport>
<DebuggerSupport Condition="'$(DebuggerSupport)' == '' and '$(Configuration)' == 'Release' and '$(BlazorWebAssemblyEnableDebugging)' != 'true'">false</DebuggerSupport>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any thoughts on the rule here? Removing "debug only" code, I've seen over 100 KB (uncompressed) size savings in a default template app.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is perfect:

  • In Release builds we want as small as possible (and debugging is definitely optional in that case)
  • In Debug builds we want nice debugging UX

Comment on lines +31 to +33
<EventSourceSupport Condition="'$(EventSourceSupport)' == ''">false</EventSourceSupport>
<UseSystemResourceKeys Condition="'$(UseSystemResourceKeys)' == ''">true</UseSystemResourceKeys>
<EnableUnsafeUTF7Encoding Condition="'$(EnableUnsafeUTF7Encoding)' == ''">false</EnableUnsafeUTF7Encoding>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I know it's not related to this change, but it just caught my eye... the naming is so inconsistent. We have "SomethingSupport" then "UseSomething" and then also "EnableSomething". Would be nice to have some system to this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference between "SomethingSupport" and "EnableSomething" is what the default behavior is. By default, "EventSource", "Debugger", and "HttpActivityPropagation" are all supported by default. UTF7 Encoding is disabled by default, and you need to enable it to use it.

Since the default is enabled, it wouldn't make sense to say EnableDebugger. The corresponding word would be DisableDebugger, but I got feedback in dotnet/runtime#37288 (comment) to make it a positive name, and not a negative name. So I followed the same naming with EventSource and HttpActivityPropagation.

Side Note on EnableUnsafeUTF7Encoding: ILLink.Substitutions + default feature switch values don't work very well with the way we link the runtime libraries during the build. We would need a way to ignore the substitution during the runtime build, but still embed it into the assembly. I had a conversation with @sbomer about this, and we decided that for now, setting EnableUnsafeUTF7Encoding to the default value here is probably the best option for 5.0.

UseSystemResourceKeys is a bit of an outlier. It isn't a "support" or an "enable". It kind of fits in an "Other" category with InvariantGlobalization.

Any suggestions on how to make this better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe EnableSystemResourceTrim - but it's not exactly the same...
Honestly I'm just glad we obviously thought about it 😄

Re having susbtitutions which are not applied during library build - I would have to think about this some more, but I'm definitely willing to add something to the linker to make this possible. CoreFx is special in that we ship the linked binaries, but I do expect other libraries to run linker for the purposes of analysis - so they might run into similar problem.

@pranavkm pranavkm added this to the 5.0.0-preview8 milestone Jul 15, 2020
@ghost
Copy link

ghost commented Jul 15, 2020

Hello @pranavkm!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 7b42cf1 into dotnet:master Jul 16, 2020
@eerhardt eerhardt deleted the Fix23716 branch July 16, 2020 01:44
eerhardt added a commit to eerhardt/aspnetcore that referenced this pull request Jul 16, 2020
* Default new runtime feature switches

These new feature switches have been added to the runtime to make applications smaller. Setting reasonable defaults to Blazor wasm projects.

Fix dotnet#23716

* PR feedback
mkArtakMSFT pushed a commit that referenced this pull request Jul 16, 2020
* Default new runtime feature switches

These new feature switches have been added to the runtime to make applications smaller. Setting reasonable defaults to Blazor wasm projects.

Fix #23716

* PR feedback
pranavkm added a commit that referenced this pull request Aug 20, 2020
Porting #23932 to WebAssemblySDK.

* Default new runtime feature switches

These new feature switches have been added to the runtime to make applications smaller. Setting reasonable defaults to Blazor wasm projects.

Fixes #25099

If there is an ask mode template to fill out, let me know and I can do it.
pranavkm added a commit that referenced this pull request Aug 21, 2020
Porting #23932 to WebAssemblySDK.

* Default new runtime feature switches

These new feature switches have been added to the runtime to make applications smaller. Setting reasonable defaults to Blazor wasm projects.

Fixes #25099

If there is an ask mode template to fill out, let me know and I can do it.
ghost pushed a commit that referenced this pull request Aug 22, 2020
Porting #23932 to WebAssemblySDK.

* Default new runtime feature switches

These new feature switches have been added to the runtime to make applications smaller. Setting reasonable defaults to Blazor wasm projects.

Fixes #25099

If there is an ask mode template to fill out, let me know and I can do it.
dougbu pushed a commit to dougbu/razor-compiler that referenced this pull request Nov 17, 2021
* Default new runtime feature switches

These new feature switches have been added to the runtime to make applications smaller. Setting reasonable defaults to Blazor wasm projects.

Fix dotnet/aspnetcore#23716

* PR feedback

Commit migrated from dotnet/aspnetcore@7b42cf1275b2
dougbu pushed a commit to dougbu/razor-compiler that referenced this pull request Nov 17, 2021
…t/aspnetcore#23987)

* Default new runtime feature switches

These new feature switches have been added to the runtime to make applications smaller. Setting reasonable defaults to Blazor wasm projects.

Fix dotnet/aspnetcore#23716

* PR feedback

Commit migrated from dotnet/aspnetcore@427bfc8d6b05
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blazor WASM apps should default new runtime config options to link out unnecessary code
4 participants