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

Switch to ToImmutableAndClear #73010

Merged
merged 40 commits into from
Apr 13, 2024

Conversation

CyrusNajmabadi
Copy link
Member

ToImmutableAndClear is better than ToImmutable when the builder isn't needed any more. It will allow moving of the underlying array if the count and capacity is the same, avoiding a copy.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 13, 2024
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review April 13, 2024 03:28
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner April 13, 2024 03:28
@CyrusNajmabadi
Copy link
Member Author

@ToddGrun ptal.

}

using var statements = TemporaryArray<SyntaxNode>.Empty;
Copy link
Contributor

Choose a reason for hiding this comment

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

statements

I hesitated making suggestions to switch to TemporaryArray in non-trivial codepaths, as it seems like it would be easy for the code to end up adding a couple more entries and no longer being in a happy path.

What are your thoughts on adding a debug only assert into TemporaryArray in the case where it ends up exceeding the happy path size threshold to track down misuses of that class?

Copy link
Member Author

Choose a reason for hiding this comment

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

we should talk to sam about that, and do in another PR :)

imo, i'm wary abotu it. because maybe you have a case that is 1 elements 99% of the time, but very rarely you go up to >4. TempArray is great for that purpose.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess my thought is that if I see a loop in the code, TemporaryArray is essentially not a good choice. I feel like those cases can just ArrayBuilder or FixedSizeArrayBuilder and work almost as well. I just feel like TemporaryArray is too easy to move off the happy path without realizing it, and if I have to give up that case you mentioned to not have to worry about that, I'm ok with that.

Copy link
Member Author

Choose a reason for hiding this comment

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

there is no loop here. this is 'CreateEqualsMethod' which is either 1, 2, or 3 statemnets depending on the form we're ccreating.

Copy link
Member Author

Choose a reason for hiding this comment

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

I hesitated making suggestions to switch to TemporaryArray in non-trivial codepaths,

i agree with that. i only switched to TempArray where i thought it was trivial. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think our thoughts on this code being trivial differ :) .

Copy link
Member Author

Choose a reason for hiding this comment

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

fair enough. i thought it was trivial here, likely because i know what thsi feature does well :)

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

@CyrusNajmabadi CyrusNajmabadi merged commit bc83d42 into dotnet:main Apr 13, 2024
27 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 13, 2024
@CyrusNajmabadi CyrusNajmabadi deleted the toImmutableAndClear branch April 14, 2024 03:35
@dibarbet dibarbet modified the milestones: Next, 17.11 P1 Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants