Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

RuntimeHelpers.CreateSpan optimization for stackalloc#57123

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@svick
Copy link
Contributor

@svicksvick commentedOct 13, 2021
edited
Loading

This PR changes the IL generated forstackalloc in the following way:

  • If an existing optimization applies (loadingbyte arrays directly from PE data; usinginitblk when all bytes are the same), there is no change.
  • Otherwise, if it's converted toReadOnlySpan<T> and all initializers are constant, the wholestackalloc is replaced by a call toCreateSpan.
  • Otherwise (e.g. when converted toSpan<T> or when only some initializers are constant),CreateSpan is used as a part of regularstackalloc codegen, together withcpblk.

The IL for array initializers is also changed:

  • If an array initializer for a type larger thanbyte with all initializers constant is converted to ROS, the whole expression is replaced withCreateSpan.

There are still some questions I have and things that would need addressing to make this code production quality:

  1. Is it okay to callGetPinnableReference (without any pinning) to get the backing data for the result ofCreateSpan, for use incpblk?
  2. Alignment. As I understand it, the compiler currently does not align the metadata blocks containing initialization data in any way. If this is a requirement, that would need to change.
  3. ENC. This optimization does not work with ENC and the code needs to know whether to apply this optimization at the lowering stage. But I don't know how to find out if ENC is used from inside ofLocalRewriter. Is there some way to do that?

steveharter reacted with eyes emoji
@ghostghost added CommunityThe pull request was submitted by a contributor who is not a Microsoft employee. Area-Compilers labelsOct 13, 2021
@svicksvickforce-pushed theinitializespan-helper branch from972aacf to0f2120dCompareOctober 13, 2021 18:13
@svicksvickforce-pushed theinitializespan-helper branch 3 times, most recently from83489e2 to609cba8CompareOctober 13, 2021 20:35
@svicksvickforce-pushed theinitializespan-helper branch from609cba8 to432d5e0CompareOctober 13, 2021 22:22
@svicksvickforce-pushed theinitializespan-helper branch from804a997 to654aba8CompareOctober 14, 2021 13:42
@svicksvick marked this pull request as ready for reviewOctober 14, 2021 14:57
@svicksvick requested a review froma team as acode ownerOctober 14, 2021 14:57
@svicksvickforce-pushed theinitializespan-helper branch from70dd5b4 tode12627CompareOctober 14, 2021 17:31
Copy link
Member

@RikkiGibsonRikkiGibson left a comment

Choose a reason for hiding this comment

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

cool!

@cstoncston merged commit4f9e976 intodotnet:demos/lowlevelhackathonOct 14, 2021
@cston
Copy link
Contributor

Thanks@svick!

@svicksvick deleted the initializespan-helper branchOctober 14, 2021 19:04
@alrz
Copy link
Member

alrz commentedApr 23, 2022
edited
Loading

lowlevelhackathon

So this is not supposed to reach main?

@svick
Copy link
ContributorAuthor

@alrz

So this is not supposed to reach main?

It is, at some point. As far as I can see, the required runtime code is ready (dotnet/runtime#60948 (comment)), so I think the next step would be to get answers to the questions I had above and then this could be probably merged into main.

I don't know if I'm going to be able to do that soon.

@jaredpar
Copy link
Member

It's on the list of features we're trying to get into C# 11. This feature is mostly in the "just need to find some keyboard time" vs. "needs a lot of design". That is why we've pushed it further back in the schedule as we've prioritized items that need more design work.

The schedule is very tight right now though as we had a number of last second asks that we're dealing with.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@RikkiGibsonRikkiGibsonRikkiGibson approved these changes

+1 more reviewer

@cstoncstoncston approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

Area-CompilersCommunityThe pull request was submitted by a contributor who is not a Microsoft employee.

Projects

Archived in project

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@svick@cston@alrz@jaredpar@RikkiGibson

[8]ページ先頭

©2009-2025 Movatter.jp