You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The use of source generation via IIncrementalGenerator and the C#12 preview feature "interceptors" may be able to improve Spectre.Console's performance by a non-trivial amount.
Interceptors allow for compile-time rerouting of method calls to different code. This means that, for example, a call to AnsiConsole.MarkupLine could be intercepted and instead a call to Console.WriteLine with the parsed markup can be inserted instead. This requires source generation of each parsed call to AnsiConsole.MarkupLine.
As an example, take a simple Program.cs like this;
using Spectre.Console;
AnsiConsole.MarkupLine("[Green]Hello, world![/])");
A source generator would pick up this call to AnsiConsole.MarkupLine, perform the markup parsing, and would generate an interceptor such as this;
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The use of source generation via
IIncrementalGenerator
and the C#12 preview feature "interceptors" may be able to improveSpectre.Console
's performance by a non-trivial amount.Interceptors allow for compile-time rerouting of method calls to different code. This means that, for example, a call to
AnsiConsole.MarkupLine
could be intercepted and instead a call toConsole.WriteLine
with the parsed markup can be inserted instead. This requires source generation of each parsed call toAnsiConsole.MarkupLine
.As an example, take a simple
Program.cs
like this;A source generator would pick up this call to
AnsiConsole.MarkupLine
, perform the markup parsing, and would generate an interceptor such as this;This would allow for the parsing of markup commands to happen at compile time and would speed up execution.
Beta Was this translation helpful? Give feedback.
All reactions