Reading Large Additional Files in Incremental Source Generators #71441
-
Hi! I am writing an Here are the broad strokes of my code: IncrementalValueProvider<string> fileHeader = context
.AnalyzerConfigOptionsProvider
.Select(static (provider, _) => /* Return file_header_template from .globalconfig */);
IncrementalValueProvider<ImmutableArray</* Table Row */>> dataElements = context
.AdditionalTextsProvider
.Where(static text => string.Equals(Path.GetFileName(text.Path), "<my file>", StringComparison.Ordinal))
.SelectMany(static (text, token) => /* Parse rows from HTML table */)
.Collect();
context.RegisterSourceOutput(
dataElements.Combine(fileHeader),
static (c, pair) => c.AddSource($"<source>.g.cs", /* Writes source based on header and rows */)); Some things I checked or thought of include:
Is there an idiomatic way or best practice for dealing with large files? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The incremental pipeline is only used in Visual Studio for running your generator as a part of the IDE editing experience; a command line build like dotnet build will always run the generator from scratch since we don't have a place to really persist that between runs. If you don't need to consume anything from the compilation, then you might be better off instead moving this to an MSBuild task where you could try to do version checking and reuse a previously generated result. Have you tried running your generator under a profiler? Which part is slow? |
Beta Was this translation helpful? Give feedback.
The incremental pipeline is only used in Visual Studio for running your generator as a part of the IDE editing experience; a command line build like dotnet build will always run the generator from scratch since we don't have a place to really persist that between runs. If you don't need to consume anything from the compilation, then you might be better off instead moving this to an MSBuild task where you could try to do version checking and reuse a previously generated result.
Have you tried running your generator under a profiler? Which part is slow?