-
Notifications
You must be signed in to change notification settings - Fork 779
Fixes #5310. Add ConfigurationManager / Scheme / Theme benchmark baseline #5312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
810628d
Initial plan
Copilot 4753931
Add ConfigurationManager / Scheme / Theme benchmark baseline
Copilot 8c099fb
Remove local_packages build artifacts and add to .gitignore
Copilot 0ae15fe
Restore local_packages and .gitignore to original state
Copilot 7d1e9f6
Fix benchmarks to reset state per invocation, not per iteration
Copilot f0f2b54
Remove accidentally committed 1.0.0 nupkg build artifacts from local_…
Copilot 7cf0489
Update baseline.json with real benchmark numbers from actual run
Copilot e582153
Remove accidentally re-added 1.0.0 nupkg build artifacts
Copilot 529d1d5
Fix README --filter syntax: use space-separated globs instead of pipe…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Tests/Benchmarks/Configuration/ConfigurationManagerLoadBenchmark.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| using BenchmarkDotNet.Attributes; | ||
| using Terminal.Gui.Configuration; | ||
|
|
||
| namespace Terminal.Gui.Benchmarks.Configuration; | ||
|
|
||
| /// <summary> | ||
| /// Measures the cold-start cost of loading the embedded library configuration: | ||
| /// <c>ConfigurationManager.Disable (true)</c> → <c>Enable (ConfigLocations.LibraryResources)</c> → <c>Apply ()</c>. | ||
| /// This is the app-startup hot path. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// Run: | ||
| /// <code>dotnet run --project Tests/Benchmarks -c Release -- --filter '*ConfigurationManagerLoad*'</code> | ||
| /// </para> | ||
| /// </remarks> | ||
| [MemoryDiagnoser] | ||
| [BenchmarkCategory ("Configuration")] | ||
| public class ConfigurationManagerLoadBenchmark | ||
| { | ||
| /// <summary> | ||
| /// Loads the embedded library configuration from scratch and applies it. | ||
| /// Captures the full deserialize + merge + apply path. | ||
| /// Calls <see cref="ConfigurationManager.Disable"/> first so every invocation | ||
| /// is a true cold start (<see cref="ConfigurationManager.Enable"/> short-circuits when already enabled). | ||
| /// </summary> | ||
| [Benchmark] | ||
| public void LoadAndApply () | ||
| { | ||
| ConfigurationManager.Disable (true); | ||
| ConfigurationManager.Enable (ConfigLocations.LibraryResources); | ||
| ConfigurationManager.Apply (); | ||
| } | ||
|
|
||
| /// <summary>Ensures ConfigurationManager is disabled after all iterations.</summary> | ||
| [GlobalCleanup] | ||
| public void Cleanup () | ||
| { | ||
| ConfigurationManager.Disable (true); | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
Tests/Benchmarks/Configuration/SchemeAttributeBenchmark.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| using BenchmarkDotNet.Attributes; | ||
| using Terminal.Gui.Drawing; | ||
| using TgAttribute = Terminal.Gui.Drawing.Attribute; | ||
|
|
||
| namespace Terminal.Gui.Benchmarks.Configuration; | ||
|
|
||
| /// <summary> | ||
| /// Measures <see cref="Scheme.GetAttributeForRole"/> for roles at different depths of the derivation chain: | ||
| /// <list type="bullet"> | ||
| /// <item><see cref="VisualRole.Normal"/> — explicitly set (O(1) lookup)</item> | ||
| /// <item><see cref="VisualRole.HotFocus"/> — derived from <see cref="VisualRole.Focus"/></item> | ||
| /// <item><see cref="VisualRole.Code"/> — deepest derivation (<c>Code → Editable → Normal</c>)</item> | ||
| /// </list> | ||
| /// No <see cref="Terminal.Gui.Configuration.ConfigurationManager"/> required; operates on a standalone | ||
| /// <see cref="Scheme"/> instance. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// Run: | ||
| /// <code>dotnet run --project Tests/Benchmarks -c Release -- --filter '*SchemeAttribute*'</code> | ||
| /// </para> | ||
| /// </remarks> | ||
| [MemoryDiagnoser] | ||
| [BenchmarkCategory ("Configuration", "Scheme")] | ||
| public class SchemeAttributeBenchmark | ||
| { | ||
| private Scheme _scheme = null!; | ||
|
|
||
| /// <summary>Creates a scheme with only <see cref="VisualRole.Normal"/> explicitly set.</summary> | ||
| [GlobalSetup] | ||
| public void Setup () | ||
| { | ||
| _scheme = new Scheme { Normal = new TgAttribute (Color.White, Color.Black) }; | ||
| } | ||
|
|
||
| /// <summary>Lookup for an explicitly-set role — the fastest path.</summary> | ||
| [Benchmark (Baseline = true)] | ||
| public TgAttribute GetNormal () => _scheme.GetAttributeForRole (VisualRole.Normal); | ||
|
|
||
| /// <summary>Lookup for a role derived from Focus (which itself is derived from Normal).</summary> | ||
| [Benchmark] | ||
| public TgAttribute GetHotFocus () => _scheme.GetAttributeForRole (VisualRole.HotFocus); | ||
|
|
||
| /// <summary>Lookup for the deepest derivation path: Code → Editable → Normal.</summary> | ||
| [Benchmark] | ||
| public TgAttribute GetCode () => _scheme.GetAttributeForRole (VisualRole.Code); | ||
| } |
63 changes: 63 additions & 0 deletions
63
Tests/Benchmarks/Configuration/SchemeSerializationBenchmark.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| using System.Text.Json; | ||
| using BenchmarkDotNet.Attributes; | ||
| using Terminal.Gui.Configuration; | ||
| using Terminal.Gui.Drawing; | ||
| using TgAttribute = Terminal.Gui.Drawing.Attribute; | ||
|
|
||
| namespace Terminal.Gui.Benchmarks.Configuration; | ||
|
|
||
| /// <summary> | ||
| /// Measures serialize-then-deserialize of a representative <c>Base</c> <see cref="Scheme"/> via | ||
| /// <see cref="JsonSerializer"/> and <see cref="SchemeJsonConverter"/>. Catches regressions in the JSON | ||
| /// code paths when future PRs add fields to <see cref="Scheme"/>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// Run: | ||
| /// <code>dotnet run --project Tests/Benchmarks -c Release -- --filter '*SchemeSerialization*'</code> | ||
| /// </para> | ||
| /// </remarks> | ||
| [MemoryDiagnoser] | ||
| [BenchmarkCategory ("Configuration", "Scheme")] | ||
| public class SchemeSerializationBenchmark | ||
| { | ||
| private Scheme _scheme = null!; | ||
| private string _json = null!; | ||
| private JsonSerializerOptions _options = null!; | ||
|
|
||
| /// <summary> | ||
| /// Creates a representative <c>Base</c> scheme with only <see cref="VisualRole.Normal"/> explicitly set | ||
| /// and prepares serialization options with the <see cref="SchemeJsonConverter"/>. | ||
| /// </summary> | ||
| [GlobalSetup] | ||
| public void Setup () | ||
| { | ||
| _scheme = new Scheme { Normal = new TgAttribute (Color.White, Color.Black) }; | ||
|
|
||
| _options = new JsonSerializerOptions | ||
| { | ||
| Converters = { new SchemeJsonConverter () }, | ||
| PropertyNameCaseInsensitive = true | ||
| }; | ||
|
|
||
| // Pre-serialize to have a stable JSON string for deserialization benchmarks. | ||
| _json = JsonSerializer.Serialize (_scheme, _options); | ||
| } | ||
|
|
||
| /// <summary>Serializes a <see cref="Scheme"/> to JSON.</summary> | ||
| [Benchmark] | ||
| public string Serialize () => JsonSerializer.Serialize (_scheme, _options); | ||
|
|
||
| /// <summary>Deserializes a <see cref="Scheme"/> from JSON.</summary> | ||
| [Benchmark] | ||
| public Scheme? Deserialize () => JsonSerializer.Deserialize<Scheme> (_json, _options); | ||
|
|
||
| /// <summary>Full round-trip: serialize then immediately deserialize.</summary> | ||
| [Benchmark (Baseline = true)] | ||
| public Scheme? RoundTrip () | ||
| { | ||
| string json = JsonSerializer.Serialize (_scheme, _options); | ||
|
|
||
| return JsonSerializer.Deserialize<Scheme> (json, _options); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| using BenchmarkDotNet.Attributes; | ||
| using Terminal.Gui.Configuration; | ||
|
|
||
| namespace Terminal.Gui.Benchmarks.Configuration; | ||
|
|
||
| /// <summary> | ||
| /// Measures the cost of switching the active theme via | ||
| /// <c>ThemeManager.Theme = "X"; ConfigurationManager.Apply ()</c>. | ||
| /// Parametric over every built-in theme name shipped in the embedded <c>config.json</c>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// Run: | ||
| /// <code>dotnet run --project Tests/Benchmarks -c Release -- --filter '*ThemeSwitch*'</code> | ||
| /// </para> | ||
| /// </remarks> | ||
| [MemoryDiagnoser] | ||
| [BenchmarkCategory ("Configuration", "Theme")] | ||
| public class ThemeSwitchBenchmark | ||
| { | ||
| /// <summary>The built-in theme to switch to during each benchmark invocation.</summary> | ||
| [ParamsSource (nameof (ThemeNames))] | ||
| public string ThemeName { get; set; } = ThemeManager.DEFAULT_THEME_NAME; | ||
|
|
||
| /// <summary>Returns the set of built-in theme names available after loading library resources.</summary> | ||
| public static IEnumerable<string> ThemeNames | ||
| { | ||
| get | ||
| { | ||
| ConfigurationManager.Disable (true); | ||
| ConfigurationManager.Enable (ConfigLocations.LibraryResources); | ||
|
|
||
| IEnumerable<string> names = ThemeManager.GetThemeNames (); | ||
|
|
||
| ConfigurationManager.Disable (true); | ||
|
|
||
| return names; | ||
| } | ||
| } | ||
|
|
||
| /// <summary>Loads the embedded configuration so all built-in themes are available.</summary> | ||
| [GlobalSetup] | ||
| public void Setup () | ||
| { | ||
| ConfigurationManager.Disable (true); | ||
| ConfigurationManager.Enable (ConfigLocations.LibraryResources); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Switches the active theme and applies the change. | ||
| /// This is the user-facing hot path when cycling themes via a <see cref="Views.Shortcut"/>. | ||
| /// Resets to <see cref="ThemeManager.DEFAULT_THEME_NAME"/> before each switch so every | ||
| /// invocation performs a real theme change (not a redundant reapply). | ||
| /// </summary> | ||
| [Benchmark] | ||
| public void SwitchTheme () | ||
| { | ||
| ThemeManager.Theme = ThemeManager.DEFAULT_THEME_NAME; | ||
| ConfigurationManager.Apply (); | ||
|
|
||
| ThemeManager.Theme = ThemeName; | ||
| ConfigurationManager.Apply (); | ||
| } | ||
|
|
||
| /// <summary>Ensures ConfigurationManager is disabled after all iterations.</summary> | ||
| [GlobalCleanup] | ||
| public void Cleanup () | ||
| { | ||
| ConfigurationManager.Disable (true); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.