mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
Reduce string allocations in IConsoleOutput implementations (#3978)
* Change IConsoleOutput.Write(string) overload parameter to ReadOnlySpan<char> Allows the caller more flexibility about choosing a buffer per use case. * NetOutput: Write StringBuilder directly to the std out text stream * Add EscSeqUtils.CSI_WriteCursorPosition Writes cursor position sequence to text writer without string allocation. * NetOutput: Skip cursor position escape sequence string allocation * Replace CSI_(Enable|Disable)MouseEvents static properties with readonly fields Changed for the sake of consistency with rest of the EscSegutils fields rather than performance. Also prevents bugs from accidentally setting the properties. * Use EscSeqUtils.CSI_Append(Foreground|Background)ColorRGB in v2 drivers * WindowsOutput SetCursorVisibility: Remove intermediate string builder * WindowsOutput.WriteToConsole: Use rented array as intermediate write buffer The large intermediate string builder remains a challenge. :) * NetOutput: Console.Out for the sake of consistency Also might have missed one of the Console.Out.Write(StringBuilder) calls... * Avoid Rune.ToString() in NetOutput.Write(IOutputBuffer) --------- Co-authored-by: Tig <tig@users.noreply.github.com>
This commit is contained in:
31
Benchmarks/ConsoleDrivers/EscSeqUtils/CSI_SetVsWrite.cs
Normal file
31
Benchmarks/ConsoleDrivers/EscSeqUtils/CSI_SetVsWrite.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Tui = Terminal.Gui;
|
||||
|
||||
namespace Terminal.Gui.Benchmarks.ConsoleDrivers.EscSeqUtils;
|
||||
|
||||
[MemoryDiagnoser]
|
||||
// Hide useless column from results.
|
||||
[HideColumns ("writer")]
|
||||
public class CSI_SetVsWrite
|
||||
{
|
||||
[Benchmark (Baseline = true)]
|
||||
[ArgumentsSource (nameof (TextWriterSource))]
|
||||
public TextWriter Set (TextWriter writer)
|
||||
{
|
||||
writer.Write (Tui.EscSeqUtils.CSI_SetCursorPosition (1, 1));
|
||||
return writer;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
[ArgumentsSource (nameof (TextWriterSource))]
|
||||
public TextWriter Write (TextWriter writer)
|
||||
{
|
||||
Tui.EscSeqUtils.CSI_WriteCursorPosition (writer, 1, 1);
|
||||
return writer;
|
||||
}
|
||||
|
||||
public static IEnumerable<object> TextWriterSource ()
|
||||
{
|
||||
return [StringWriter.Null];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user