Skip to content

Commit

Permalink
feat: perform warmup emit when connection is established
Browse files Browse the repository at this point in the history
  • Loading branch information
rdavisau committed Jun 8, 2022
1 parent 3254a01 commit 5b663ba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Expand Up @@ -126,6 +126,10 @@ public async Task SetupReferenceTracking()

foreach (var refSeen in existingReferences.Select(x => x.AssemblyLocation))
seen.Add(refSeen);

// allow a little time for references to come back <:-)
// should have client tell us when all current dependencies have been sent
Task.Delay(TimeSpan.FromSeconds(.33)).ContinueWith(_ => IncrementalCompiler.DoWarmup());
}

if (targetHello.UseDependencyCache && targetHello.ApplicationIdentifier is { } appIdentifier)
Expand Down
Expand Up @@ -17,5 +17,6 @@ public interface IIncrementalCompiler
void ClearTrees();
void PrintTrees(bool withDetail);
string TryResolvePrimaryType(string typeHint);
void DoWarmup();
}
}
Expand Up @@ -295,6 +295,26 @@ private bool TryApplyCompilationFixers(EmitResult result, CSharpCompilation curr
return false;
}
}

public void DoWarmup()
{
var sw = Stopwatch.StartNew();
try
{
StageFile(new ChangedFile {
Path = "warmup",
Contents = "public class Warm { public string Warmup { get; set; } }",
ChangedAt = DateTimeOffset.UtcNow });

foreach (var c in _compilationFixers.Values)
c.TryFix(CurrentCompilation, new(), out _);
}
catch (Exception ex) { Logger.LogError(ex, "Warmup"); }

TryRemoveTree("warmup");

Logger.LogInformation("Warmup emit completed in {Elapsed}", sw.Elapsed);
}

private void WithCompilation(Func<CSharpCompilation, CSharpCompilation> action)
{
Expand Down

0 comments on commit 5b663ba

Please sign in to comment.