Skip to content

Immediately filter syntax trees down to those that either have attributes or global-using-aliases.#62483

Merged
CyrusNajmabadi merged 81 commits intodotnet:mainfrom
CyrusNajmabadi:prefilterTrees
Jul 12, 2022
Merged

Immediately filter syntax trees down to those that either have attributes or global-using-aliases.#62483
CyrusNajmabadi merged 81 commits intodotnet:mainfrom
CyrusNajmabadi:prefilterTrees

Conversation

@CyrusNajmabadi
Copy link
Contributor

@CyrusNajmabadi CyrusNajmabadi commented Jul 7, 2022

Followup to #62389

Cuts down CPU time from 3.4 to 1.4seconds (58% improvement).
Cuts down memory from 1.3GB:

image

To 0.5GB (60% improvement):

image

--

At this point all memory is contained here:

image

Which are the SyntaxTree arrays the compilation itself points at. We can only improve on this if we change the underlying storage for a Compilation to something better on memory usage (like a ImmutableList).

CyrusNajmabadi and others added 30 commits June 30, 2022 12:52
/// the number of *relevant syntax trees*. This can lead to huge memory churn keeping track of a high number of
/// trees, most of which are not going to be relevant.
/// </summary>
private static readonly ConditionalWeakTable<SyntaxTree, SyntaxTreeInfo> s_treeToInfo = new();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: as an alternative to a CWT, i could also use a normal dictionary created inside ForAttributeWithSimpleName and then captured. But i wasn't certain what the semantics were for the lifetimes of these pipelines. @chsienki what are the lifetimes? And are the pipelines executed concurrently?

}

private IEnumerable<int> YieldItems(OneOrMany<int> items)
private static IEnumerable<int> YieldItems(OneOrMany<int> items)
Copy link
Member

Choose a reason for hiding this comment

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

nit: do we need this at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alternative recommendation?

Copy link
Member

Choose a reason for hiding this comment

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

Places that use this can use GetEnumerator instead of YieldItems, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unfortunately no, that returns an Enumerator/IEnumerator. The test helpers test IEnumerables. I could make OneOrMany IEnumerable, but it seemed excessive (and potentially worrying for boxing reasons) just for test purposes.

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

Done with review pass (iteration 76)

@CyrusNajmabadi
Copy link
Contributor Author

@chsienki PTAL

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 80)

@RikkiGibson RikkiGibson self-assigned this Jul 11, 2022
Copy link
Member

@RikkiGibson RikkiGibson left a comment

Choose a reason for hiding this comment

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

LGTM. There are 80 commits here, compared to 96 lines added, which we will need to scroll past if we need to search the history on GitHub for build-breaking issues, etc. Consider consolidating those commits somehow, e.g. via interactive rebase, or by squash merge.

.SelectMany(static (c, _) => c.SyntaxTrees)
.SelectMany((compilation, cancellationToken) => compilation.SyntaxTrees
.Select(tree => GetTreeInfo(tree, syntaxHelper, cancellationToken))
.Where(info => info.ContainsGlobalAliases || info.ContainsAttributeList))
Copy link
Member

Choose a reason for hiding this comment

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

Did you consider adding flags to SyntaxTree instead? Wondering about what the tradeoffs would be.

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'm definitely considering that (And talked to julien about just that). i'm going to separate into a distinct PR as the bleeding into SyntaxTree feels like something to consider outside of this. Will do next.

@CyrusNajmabadi
Copy link
Contributor Author

Consider consolidating those commits somehow, e.g. via interactive rebase, or by squash merge.

Yup. It's set to squash-merge.

@CyrusNajmabadi CyrusNajmabadi enabled auto-merge (squash) July 11, 2022 23:02
@CyrusNajmabadi CyrusNajmabadi merged commit 7e2478f into dotnet:main Jul 12, 2022
@ghost ghost added this to the Next milestone Jul 12, 2022
adamperlin pushed a commit to adamperlin/roslyn that referenced this pull request Jul 19, 2022
…utes or global-using-aliases. (dotnet#62483)

* Cache the hash in compilation options

* Remove

* Update src/Compilers/Core/Portable/InternalUtilities/Hash.cs

* Update src/Compilers/Core/Portable/InternalUtilities/Hash.cs

* Update src/Compilers/Core/Portable/InternalUtilities/Hash.cs

* Fix api

* Walk green-nodes in incremental-generator attribute-finding path

* Use green nodes

* REmove

* Fix tests

* Avoid allocating builder if not needed

* Simplify

* Only loop once

* Do not look for load/reference directives when there can't be any

* REmove use of Lazy in DeclarationTable for rarely used values.

* Remove lazy

* In progress

* Change the data-flow path for searching for attributes to prevent fewer intermediary tables.

* Remove unused type

* Simplify

* Update tests

* Make internal

* Update

* Update src/Compilers/Core/Portable/SourceGeneration/Nodes/NodeStateTable.cs

* Update comment

* Filter large tables before processing htem.

* Update tests

* Sort

* Fix grammar

* Fix assert

* Add back in

* Revert

* Simplify

* remove

* Simplify

* Remove

* Simplify global aliases

* Prefilter to only trees that have attributes or globalaliases in them

* INcrease

* Only check the top level for global usings.

* Remove comment

* Simplify

* Add docs

* Revert

* Make static

* Extract common code

* PR feedback

* Use helper

* update run counts

* Chain compilations

* Fix grammar

* Don't use implicit construction

* Fix

* Tweak benchmark

* Simplify walk
@allisonchou allisonchou modified the milestones: Next, 17.4 P1 Jul 26, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the prefilterTrees branch February 9, 2023 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants