dotnet / roslyn-analyzers

MIT License
1.58k stars 464 forks source link

IIncrementalGenerator: Use Combine efficiently #6581

Open sharwell opened 1 year ago

sharwell commented 1 year ago

Describe the problem you are trying to solve

When combining IIncrementalValuesProvider<T> with two or more IIncrementalValueProvider<T> instances, the manner in which the values are combined can impact cache sizes.

Describe suggestions on how to achieve the rule

Identify cases where the following pattern is used:

values.Combine(value1).Combine(value2)

Suggest to rewrite as:

values.Combine(value1.Combine(value2))

Additional context

https://github.com/dotnet/roslyn-analyzers/commit/e9db5f601bb5a676dc078d90ac26488846f09691

CyrusNajmabadi commented 1 year ago

values.Collect(value1).Collect(value2)

Combine not Collect, right?

sharwell commented 1 year ago

📝 Before implementing this rule as an analyzer, we will investigate if it's possible for the incremental generator driver to perform the optimization by simply never caching the output of Combine if it's only used by a downstream call to Combine.