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

Convert interval-tree type to a struct #73676

Merged
merged 8 commits into from
May 25, 2024

Conversation

CyrusNajmabadi
Copy link
Member

This drops us from a total of 4.7% of all allocations:

image

Down to just 2.1%

image

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner May 23, 2024 20:32
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels May 23, 2024
{
public readonly TTag Tag = ts.Tag;
public readonly ITrackingSpan Span = ts.Span.CreateTrackingSpan(trackingMode);
Copy link
Member Author

Choose a reason for hiding this comment

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

note: i intentionally removed the up front allocation of the tracking span. The tracking is done on demand, only for the short period of times where we have a tag and want to map it forward, and haven't produced the updated the new tags yet. I tried typing as well, and didn't see any of the tracking even showing up. This is likely because we only ever have a short distance between the original text snapshot and the latest one. So tracking from the original to the latest is extremely fast and simple without hte need for a dedicated allocated tracking span.

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 also didn't move to a model where we compute and cache this on demand because i wanted to make this a struct, and having this be a mutable struct was non-trivial in terms of ensuring it could mutate through all the interfaces and dispatch pattern we work with.

@CyrusNajmabadi
Copy link
Member Author

@ToddGrun ptal.

}

public int GetStart(ITextSnapshot textSnapshot)
Copy link
Contributor

Choose a reason for hiding this comment

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

GetStart

Could this just be a GetSpan method instead, encouraging callers to not need to call both of these (which might help in the case where a translation is necessary)

Copy link
Contributor

Choose a reason for hiding this comment

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

Duh, that's what GetTranslatedSpan is. I guess the question is why even have GetStart/GetLength

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 way interval trees work, we have a lot of algorithms that don't need the full span. that said, i'll clean this up a bit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Even if they don't need the full span, isn't calling GetTranslatedSpan the same cost as calling GetStart or GetLength individually?

The thought I had was if the GetStart/GetLength methods were removed, then callers that need one will just call the GetTranslatedSpan and use the appropriate Length/Start. Callers that need both can be trivially changed to just call GetTranslatedSpan once and use that result to get both the length and start.

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 think we need to chat.

Copy link
Member Author

Choose a reason for hiding this comment

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

Note: my primary goals in all of these are not to make large scale refactorings to the components, but to address the stuff that profiles are calling out as a problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I get that. This is definitely better, and I'm going to go ahead and approve.

Maybe I'm a bit confused on what this object is doing, I might take a peek once your changes are in.

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:

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