Skip to content

Use System.Text.Json's IAsyncEnumerable support #31894

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

Merged
merged 2 commits into from
Apr 19, 2021

Conversation

pranavkm
Copy link
Contributor

@pranavkm pranavkm commented Apr 16, 2021

Description

System.Text.Json recently added support for streaming IAsyncEnumerable types based on an ask from the ASP.NET Core team. This PR enables MVC to leverage this feature.

Customer Impact

Using IAsyncEnumerable with System.Text.Json will result in data to be streamed rather than buffered and serialized.

Regression?

  • Yes
  • No

[If yes, specify the version the behavior has regressed from]

Risk

  • High
  • Medium
  • Low

[Justify the selection above]
The feature has been well-tested in the runtime. This is simply removing additional buffering that was previously performed by MVC before invoking the serializer.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

Addresses #11558 #23203

@pranavkm pranavkm requested a review from javiercn as a code owner April 16, 2021 23:50
@ghost ghost added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Apr 16, 2021
@pranavkm pranavkm requested a review from davidfowl April 16, 2021 23:51
Base automatically changed from darc-main-1f60ac0a-c0c1-428f-831f-d288ebac2021 to main April 17, 2021 01:13
@dotnet-maestro dotnet-maestro bot requested review from dougbu, halter73, jkotalik, Tratcher and a team as code owners April 17, 2021 01:13
@pranavkm pranavkm removed request for a team, halter73, Tratcher, dougbu and jkotalik April 17, 2021 02:07
@pranavkm pranavkm force-pushed the prkrishn/asyncenumerable branch from 846fd6f to 17ae3b8 Compare April 17, 2021 02:07
@pranavkm pranavkm removed the request for review from a team April 17, 2021 02:07
@pranavkm pranavkm force-pushed the prkrishn/asyncenumerable branch from 17ae3b8 to 5d4b871 Compare April 17, 2021 02:09
}
}
// Removed Log.
// new EventId(1, "BufferingAsyncEnumerable")
Copy link
Member

Choose a reason for hiding this comment

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

👍🏾

@davidfowl
Copy link
Member

davidfowl commented Apr 17, 2021

This PR description should say something like: IAsyncEnumerable is a serializer concern, not an MVC concern 😄. This change looks good. Can we get this into preview4?

@pranavkm pranavkm changed the base branch from main to release/6.0-preview4 April 17, 2021 14:14
@pranavkm pranavkm force-pushed the prkrishn/asyncenumerable branch from 5d4b871 to ed0af15 Compare April 17, 2021 14:14
@pranavkm pranavkm added this to the 6.0-preview4 milestone Apr 17, 2021
…msdk (#31748)

[main] Update dependencies from dotnet/efcore dotnet/runtime dotnet/emsdk


 - Update to a newer SDK

 - Skip uninstall step

 - Update NuGet version to keep up with the SDK

 - Fixup test

 - Bumping SDK in attempt to fix `dotnet new` issues

 - Try only 3 platforms

 - Try assembly info

 - using

 - Quarantine test
@@ -3,6 +3,7 @@
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<UseMonoRuntime>true</UseMonoRuntime>
Copy link
Member

Choose a reason for hiding this comment

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

Is this really related to this PR, or just something we need for another reason?

Could you clarify why we need it (and didn't before)?

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 change was ported from the PR in main: https://github.com/dotnet/aspnetcore/pull/31748/files. The targeting packs in the runtime were recently renamed and this is now required if you do not reference the BlazorWebAssembly SDK (which this project does not)

var enumerated = await reader(asyncEnumerable);
await ExecuteAsyncCore(context, result, enumerated.GetType(), enumerated);
}

Copy link
Member

@javiercn javiercn Apr 19, 2021

Choose a reason for hiding this comment

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

By doing this, are we not removing support for this on other formatters? (JSON.NET, XML)

Nevermind, I see that this has been pushed down to our two other formatters. That said, this might break people creating their own formatter?

Would it make sense for this to remain on the base class and have STJ formatter signal that it doesn't need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was one of the options I considered. The current implementation is also a bit of a whack-a-mole in that it only works for all the result types that we account for. Custom result types would have the same issue (e.g. if a user makes a XmlResult or a ProtobufResult). Given the choice of either handling it at per-formatter vs per-result, the latter seems like a better choice.

I can make an announcement since this is a breaking behavior change.

Copy link
Member

Choose a reason for hiding this comment

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

Result types derived from ObjectResult would have gotten this for free right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the ordinary case, yes. It's possible that there's also custom result executors that would negate it though.

Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

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

Code changes look good, do we have integration tests (Using test server) for this anywhere?

Copy link
Contributor Author

@pranavkm pranavkm left a comment

Choose a reason for hiding this comment

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

We have functional tests as part of https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/test/Mvc.FunctionalTests/AsyncEnumerableTestBase.cs as well as some integration tests for Json.

var enumerated = await reader(asyncEnumerable);
await ExecuteAsyncCore(context, result, enumerated.GetType(), enumerated);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was one of the options I considered. The current implementation is also a bit of a whack-a-mole in that it only works for all the result types that we account for. Custom result types would have the same issue (e.g. if a user makes a XmlResult or a ProtobufResult). Given the choice of either handling it at per-formatter vs per-result, the latter seems like a better choice.

I can make an announcement since this is a breaking behavior change.

@pranavkm pranavkm added the Servicing-consider Shiproom approval is required for the issue label Apr 19, 2021
@ghost
Copy link

ghost commented Apr 19, 2021

Hello human! Please make sure you've included the Shiproom Template in a comment or (preferably) the PR description. Also, make sure this PR is not marked as a draft and is ready-to-merge.

@davidfowl davidfowl added the breaking-change This issue / pr will introduce a breaking change, when resolved / merged. label Apr 19, 2021
@mkArtakMSFT mkArtakMSFT added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Apr 19, 2021
@mkArtakMSFT
Copy link
Contributor

Approved by tactics for preview4.

@mkArtakMSFT
Copy link
Contributor

@pranavkm is this ready to merge? let me know if you need help with merging.

@pranavkm
Copy link
Contributor Author

Yup, go for it.

@mkArtakMSFT mkArtakMSFT merged commit af70a2b into release/6.0-preview4 Apr 19, 2021
@mkArtakMSFT mkArtakMSFT deleted the prkrishn/asyncenumerable branch April 19, 2021 18:58
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 breaking-change This issue / pr will introduce a breaking change, when resolved / merged. Servicing-approved Shiproom has approved the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants