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

Use feature switch to perform hot reload trimming #32506

Merged
merged 2 commits into from
May 11, 2021

Conversation

pranavkm
Copy link
Contributor

@pranavkm pranavkm commented May 7, 2021

Contributes to dotnet/runtime#51159

@ghost ghost added the area-blazor Includes: Blazor, Razor Components label May 7, 2021
@pranavkm pranavkm force-pushed the prkrishn/update-hot-reload branch 2 times, most recently from 36b0a08 to a1e894b Compare May 7, 2021 22:18
@pranavkm pranavkm marked this pull request as ready for review May 7, 2021 22:19
@pranavkm pranavkm requested a review from a team as a code owner May 7, 2021 22:19
@pranavkm pranavkm requested a review from eerhardt May 7, 2021 22:19
@pranavkm pranavkm added this to the 6.0-preview5 milestone May 7, 2021
@pranavkm pranavkm force-pushed the prkrishn/update-hot-reload branch from a1e894b to 7bd65cf Compare May 7, 2021 22:20
<method signature="System.Void CaptureRootComponentForHotReload(Microsoft.AspNetCore.Components.ParameterView,Microsoft.AspNetCore.Components.Rendering.ComponentState)" body="stub" />
<method signature="System.Void DisposeForHotReload()" body="stub" />
</type>
<assembly fullname="Microsoft.AspNetCore.Components">
<!-- Avoid any overhead in RenderHandle.IsHotReloading by aggressively trimming it -->
<type fullname="Microsoft.AspNetCore.Components.RenderHandle">
<method signature="System.Boolean get_IsHotReloading()" body="stub" value="false" />
Copy link
Member

Choose a reason for hiding this comment

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

Should this bool use the same feature switch?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see that you changed the implementation of the RenderHandle.IsHotReloading property. Maybe this xml entry can just be removed then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we'd specifically wanted to short-circuit this one quickly since it appears as part of the rendering loop. Seems easy enough to keep it

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I follow this reasoning. The body of this method will already be trimmed to just return false since

public bool IsHotReloading => HotReloadFeature.IsSupported && (_renderer?.IsHotReloading ?? false);

will evaluate to false && (_renderer?.IsHotReloading ?? false), which is always false.

Further, the only call I see to RenderHandle.IsHotReloading is here:

protected void StateHasChanged()
{
if (_hasPendingQueuedRender)
{
return;
}
if (_hasNeverRendered || ShouldRender() || _renderHandle.IsHotReloading)

Which comes after a virtual ShouldRender() call.

So I'm not sure this entry is adding any benefit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is how it looks like in the absence of the explicit trim:

public bool IsHotReloading
{
	get
	{
		if (HotReloadFeature.IsSupported)
		{
		}
		return false;
	}
}

vs

public bool IsHotReloading => false;

StateHasChanged is part of the render-loop so it would be ideal to have it execute additional instructions it doesn't really need to.

Copy link
Member

Choose a reason for hiding this comment

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

cc @marek-safar - here's more feedback on the trimmer leaving the call to an unnecessary method after trimming. See dotnet/linker#1113

Copy link
Contributor

Choose a reason for hiding this comment

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

is part of the render-loop so it would be ideal to have it execute additional instructions it doesn't really need to.

@pranavkm the IL does not fully represent executed code. In this case, the whole method will be skipped by AOT or interpreter. We'll eventually optimize the IL as well but it's nice to have at this point because it does not affect the speed only size and the savings are small.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SteveSandersonMS FYI since having this was your initial suggestion. I can remove the entry from the substitution file in a follow up.

Copy link
Member

Choose a reason for hiding this comment

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

Cool. I didn't realise the interpreter had the ability to do things like skip empty methods. I'd be interested to know if there's a particular way we should be able to reason about what optimizations would or wouldn't happen in interpreted and AOT modes.

In any case if there's no runtime cost to having a call to an empty method that's great, and it will be nice to remove this special case from the linker config!

@pranavkm pranavkm enabled auto-merge (squash) May 10, 2021 17:27
@pranavkm pranavkm merged commit 743828a into main May 11, 2021
Copy link
Member

@SteveSandersonMS SteveSandersonMS left a comment

Choose a reason for hiding this comment

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

Nice!

@pranavkm pranavkm deleted the prkrishn/update-hot-reload branch May 11, 2021 09:53
@SteveSandersonMS
Copy link
Member

@eerhardt I just added an approval here and didn't anticipate that was going to trigger an auto-merge even though there was still one of your feedback items pending: https://github.com/dotnet/aspnetcore/pull/32506/files#r629441507

Do you still want a follow-up on that one?

Auto-merge is a bit of an awkward thing if the PR isn't already approved, because it means subsequent reviewers have to (1) check if auto-merge is present and if so, (2) make sure there's no pending feedback from anyone else before marking the PR as approved.

@eerhardt
Copy link
Member

Do you still want a follow-up on that one?

I'm fine with whatever you decide is the best approach here. I personally wouldn't have the extra entry, as I don't see any real value in it. But if you decide it is worth it, I won't block on it.

@ghost
Copy link

ghost commented May 11, 2021

Hi @eerhardt. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context.

pranavkm added a commit that referenced this pull request May 11, 2021
{
/// <summary>
/// Gets a value that determines if hot reload is supported. Currently, the <c>Debugger.IsSupported</c> feature switch is used as a proxy for this.
/// Changing to a dedicated feature switch is tracked by https://github.com/dotnet/runtime/issues/51159.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI, this was resolved. @SteveSandersonMS / @eerhardt

pranavkm added a commit that referenced this pull request May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants