[PR #11184] [MERGED] Reduce usage of Json::Value throughout Terminal.Settings.Model #28446

Open
opened 2026-01-31 09:28:34 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/11184
Author: @lhecker
Created: 9/9/2021
Status: Merged
Merged: 9/22/2021
Merged by: @undefined

Base: mainHead: dev/lhecker/settings-json-cleanup


📝 Commits (10+)

  • 20b91fb Reduce usage of Json::Value throughout Terminal.Settings.Model
  • 64896e5 Fix most unit tests
  • 1efe485 Fix several issues
  • cdf07bb Address Dustin's comments
  • 2247297 Address Carlos' comments
  • 451d7d5 Bug fixes sponsored by Dustin-chan
  • 55fb5f3 Address Carlos' comments & Add code comments
  • 35b65e6 Fix typo
  • f1b20cf Allow return value optimizations
  • e2b6e64 Merge branch 'main' into dev/lhecker/settings-json-cleanup

📊 Changes

66 files changed (+2251 additions, -5456 deletions)

View changed files

📝 .github/actions/spelling/expect/expect.txt (+3 -0)
📝 README.md (+1 -0)
📝 src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp (+244 -288)
📝 src/cascadia/LocalTests_SettingsModel/CommandTests.cpp (+0 -6)
📝 src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp (+441 -1380)
📝 src/cascadia/LocalTests_SettingsModel/JsonTestClass.h (+10 -20)
📝 src/cascadia/LocalTests_SettingsModel/KeyBindingsTests.cpp (+0 -6)
📝 src/cascadia/LocalTests_SettingsModel/ProfileTests.cpp (+138 -138)
📝 src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp (+69 -81)
📝 src/cascadia/LocalTests_SettingsModel/TerminalSettingsTests.cpp (+100 -68)
📝 src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp (+18 -27)
📝 src/cascadia/LocalTests_TerminalApp/TabTests.cpp (+12 -12)
📝 src/cascadia/TerminalApp/AppLogic.cpp (+9 -28)
📝 src/cascadia/TerminalSettingsEditor/Launch.cpp (+0 -1)
📝 src/cascadia/TerminalSettingsEditor/Launch.xaml (+1 -1)
📝 src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp (+19 -20)
📝 src/cascadia/TerminalSettingsModel/AppearanceConfig.h (+2 -3)
📝 src/cascadia/TerminalSettingsModel/AzureCloudShellGenerator.cpp (+8 -15)
📝 src/cascadia/TerminalSettingsModel/AzureCloudShellGenerator.h (+5 -7)
📝 src/cascadia/TerminalSettingsModel/BaseVisualStudioGenerator.cpp (+10 -25)

...and 46 more files

📄 Description

This commit reduces the code surface that interacts with raw JSON data,
reducing code complexity and improving maintainability.
Files that needed to be changed drastically were additionally
cleaned up to remove any code cruft that has accrued over time.

In order to facility this the following changes were made:

  • Move JSON handling from CascadiaSettings into SettingsLoader
    This allows us to use STL containers for data model instances.
    For instance profiles are now added to a hashmap for O(1) lookup.
  • JSON parsing within SettingsLoader doesn't differentiate between user,
    inbox and fragment JSON data, reducing code complexity and size.
    It also centralizes common concerns, like profile deduplication and
    ensuring that all profiles are assigned a GUID.
  • Direct JSON modification, like the insertion of dynamic profiles into
    settings.json were removed. This vastly reduces code complexity,
    but unfortunately removes support for comments in JSON on first start.
  • ColorSchemes cannot be layered. As such its LayerJson API was replaced
    with FromJson, allowing us to remove JSON-based color scheme validation.
  • Profiles used to test their wish to layer using ShouldBeLayered, which
    was replaced with a GUID-based hashmap lookup on previously parsed profiles.

Further changes were made as improvements upon the previous changes:

  • Compact the JSON files embedded binary, saving 28kB
  • Prevent double-initialization of the color table in ColorScheme
  • Making til::color getters constexpr, allow better optimizations

The result is a reduction of:

  • 48kB binary size for the Settings.Model.dll
  • 5-10% startup duration
  • 26% code for the CascadiaSettings class
  • 1% overall code in this project

Furthermore this results in the following breaking changes:

  • The long deprecated "globals" settings object will not be detected and no
    warning will be created during load.
  • The initial creation of a new settings.json will not produce helpful comments.

Both cases are caused by the removal of manual JSON handling and the
move to representing the settings file with model objects instead

PR Checklist

Validation Steps Performed

  • Out-of-box-experience is identical to before ✔️
    (Except for the settings.json file lacking comments.)
  • Existing user settings load correctly ✔️
  • New WSL instances are added to user settings ✔️
  • New fragments are added to user settings ✔️
  • All profiles are assigned GUIDs ✔️

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/11184 **Author:** [@lhecker](https://github.com/lhecker) **Created:** 9/9/2021 **Status:** ✅ Merged **Merged:** 9/22/2021 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `dev/lhecker/settings-json-cleanup` --- ### 📝 Commits (10+) - [`20b91fb`](https://github.com/microsoft/terminal/commit/20b91fbbc3de21c4ab2b9773e3c539ee4e9aface) Reduce usage of Json::Value throughout Terminal.Settings.Model - [`64896e5`](https://github.com/microsoft/terminal/commit/64896e55b78d384ed0c6fe4e025368a587b58c74) Fix most unit tests - [`1efe485`](https://github.com/microsoft/terminal/commit/1efe48504b05b8d8a68d448a0940f441af827cd5) Fix several issues - [`cdf07bb`](https://github.com/microsoft/terminal/commit/cdf07bb2bd4791909592160e266cdbb5996cae78) Address Dustin's comments - [`2247297`](https://github.com/microsoft/terminal/commit/2247297c313661cf6cc1ec1efd3af9ea9c27125e) Address Carlos' comments - [`451d7d5`](https://github.com/microsoft/terminal/commit/451d7d5e4d4848984fab595312f61ec4f6ababa2) Bug fixes sponsored by Dustin-chan - [`55fb5f3`](https://github.com/microsoft/terminal/commit/55fb5f318ef99fdaa2e8bf7061d3b8ad91d84a4d) Address Carlos' comments & Add code comments - [`35b65e6`](https://github.com/microsoft/terminal/commit/35b65e6226e55922f21a9af92fbf07e22a54b778) Fix typo - [`f1b20cf`](https://github.com/microsoft/terminal/commit/f1b20cfb28b900a776fb5c8bfb14c79fce333fbf) Allow return value optimizations - [`e2b6e64`](https://github.com/microsoft/terminal/commit/e2b6e640237a4403a05574cf8a4c5743ad3baf73) Merge branch 'main' into dev/lhecker/settings-json-cleanup ### 📊 Changes **66 files changed** (+2251 additions, -5456 deletions) <details> <summary>View changed files</summary> 📝 `.github/actions/spelling/expect/expect.txt` (+3 -0) 📝 `README.md` (+1 -0) 📝 `src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp` (+244 -288) 📝 `src/cascadia/LocalTests_SettingsModel/CommandTests.cpp` (+0 -6) 📝 `src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp` (+441 -1380) 📝 `src/cascadia/LocalTests_SettingsModel/JsonTestClass.h` (+10 -20) 📝 `src/cascadia/LocalTests_SettingsModel/KeyBindingsTests.cpp` (+0 -6) 📝 `src/cascadia/LocalTests_SettingsModel/ProfileTests.cpp` (+138 -138) 📝 `src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp` (+69 -81) 📝 `src/cascadia/LocalTests_SettingsModel/TerminalSettingsTests.cpp` (+100 -68) 📝 `src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp` (+18 -27) 📝 `src/cascadia/LocalTests_TerminalApp/TabTests.cpp` (+12 -12) 📝 `src/cascadia/TerminalApp/AppLogic.cpp` (+9 -28) 📝 `src/cascadia/TerminalSettingsEditor/Launch.cpp` (+0 -1) 📝 `src/cascadia/TerminalSettingsEditor/Launch.xaml` (+1 -1) 📝 `src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp` (+19 -20) 📝 `src/cascadia/TerminalSettingsModel/AppearanceConfig.h` (+2 -3) 📝 `src/cascadia/TerminalSettingsModel/AzureCloudShellGenerator.cpp` (+8 -15) 📝 `src/cascadia/TerminalSettingsModel/AzureCloudShellGenerator.h` (+5 -7) 📝 `src/cascadia/TerminalSettingsModel/BaseVisualStudioGenerator.cpp` (+10 -25) _...and 46 more files_ </details> ### 📄 Description This commit reduces the code surface that interacts with raw JSON data, reducing code complexity and improving maintainability. Files that needed to be changed drastically were additionally cleaned up to remove any code cruft that has accrued over time. In order to facility this the following changes were made: * Move JSON handling from `CascadiaSettings` into `SettingsLoader` This allows us to use STL containers for data model instances. For instance profiles are now added to a hashmap for O(1) lookup. * JSON parsing within `SettingsLoader` doesn't differentiate between user, inbox and fragment JSON data, reducing code complexity and size. It also centralizes common concerns, like profile deduplication and ensuring that all profiles are assigned a GUID. * Direct JSON modification, like the insertion of dynamic profiles into settings.json were removed. This vastly reduces code complexity, but unfortunately removes support for comments in JSON on first start. * `ColorScheme`s cannot be layered. As such its `LayerJson` API was replaced with `FromJson`, allowing us to remove JSON-based color scheme validation. * `Profile`s used to test their wish to layer using `ShouldBeLayered`, which was replaced with a GUID-based hashmap lookup on previously parsed profiles. Further changes were made as improvements upon the previous changes: * Compact the JSON files embedded binary, saving 28kB * Prevent double-initialization of the color table in `ColorScheme` * Making `til::color` getters `constexpr`, allow better optimizations The result is a reduction of: * 48kB binary size for the Settings.Model.dll * 5-10% startup duration * 26% code for the `CascadiaSettings` class * 1% overall code in this project Furthermore this results in the following breaking changes: * The long deprecated "globals" settings object will not be detected and no warning will be created during load. * The initial creation of a new settings.json will not produce helpful comments. Both cases are caused by the removal of manual JSON handling and the move to representing the settings file with model objects instead ## PR Checklist * [x] Closes #5276 * [x] Closes #7421 * [x] I work here * [x] Tests added/passed ## Validation Steps Performed * Out-of-box-experience is identical to before ✔️ (Except for the settings.json file lacking comments.) * Existing user settings load correctly ✔️ * New WSL instances are added to user settings ✔️ * New fragments are added to user settings ✔️ * All profiles are assigned GUIDs ✔️ --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:28:34 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#28446