shader_library: move nested JSON values during parsing #1108

Closed
Kadamitas wants to merge 1 commit from upstream-pr/1108 into main
Kadamitas commented 2026-11-24 18:38:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Kadamitas on 2026-11-24T18:38:11Z.


Claimed in the coordination issue as: RT-JSON-SUBTREE-MOVES (claim)

What and why

The explicitly defaulted destructor suppresses the implicit move constructor of Json. Passing a parsed child to a vector with std::move therefore copies its strings and nested vectors. Growing an object or array can copy those subtrees again. Letting the compiler generate the destructor restores nonthrowing moves for both Json and JsonObjectEntry. The forward declaration still supports recursive object values.

Tested

  • shader_library_test and mods_test passed under MSVC x64, GCC 11.4 and Clang 18.1.8 with libstdc++. Clang 15 with libstdc++ 11 rejects the existing C++20 aggregate construction in emplace_back on both revisions.

  • A synthetic input had 1,200 named entries, each with a label and four arrays of six small objects. Both builds produced 181,201 nodes and the same tree digest from the 1,141,381-byte document. Five interleaved release runs per revision under MSVC gave median parse times of 71.14 ms before and 17.46 ms after. Allocation counts fell from 822,984 to 176,419. File reads and digest calculation were outside the timed region.

  • git diff --check and scripts/check_no_game_data.py runtime/src/shader_library.h passed.

  • The general translator suite ran 6,168 tests across 470 files with zero failing files.

GPUs tested: n/a, CPU-only JSON parsing.

AI-assisted: yes, Codex.

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • No game data, keys or decryption.
  • Translator rule documentation is inapplicable to this parser change.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5478142210 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1108). Originally posted by [Kadamitas](https://github.com/Kadamitas) on 2026-11-24T18:38:11Z. --- Claimed in the coordination issue as: RT-JSON-SUBTREE-MOVES ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7140842004)) ### What and why The explicitly defaulted destructor suppresses the implicit move constructor of `Json`. Passing a parsed child to a vector with `std::move` therefore copies its strings and nested vectors. Growing an object or array can copy those subtrees again. Letting the compiler generate the destructor restores nonthrowing moves for both `Json` and `JsonObjectEntry`. The forward declaration still supports recursive object values. ### Tested - `shader_library_test` and `mods_test` passed under MSVC x64, GCC 11.4 and Clang 18.1.8 with libstdc++. Clang 15 with libstdc++ 11 rejects the existing C++20 aggregate construction in `emplace_back` on both revisions. - A synthetic input had 1,200 named entries, each with a label and four arrays of six small objects. Both builds produced 181,201 nodes and the same tree digest from the 1,141,381-byte document. Five interleaved release runs per revision under MSVC gave median parse times of 71.14 ms before and 17.46 ms after. Allocation counts fell from 822,984 to 176,419. File reads and digest calculation were outside the timed region. - `git diff --check` and `scripts/check_no_game_data.py runtime/src/shader_library.h` passed. - The general translator suite ran 6,168 tests across 470 files with zero failing files. GPUs tested: n/a, CPU-only JSON parsing. AI-assisted: yes, Codex. ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic. - [x] No game data, keys or decryption. - [x] Translator rule documentation is inapplicable to this parser change.
abnalstlll-byte commented 2026-11-24 18:38:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T18:38:36Z.

Review: APPROVED


Audited and verified. Removing the user-declared destructor allows the compiler to generate implicit move constructors and move assignment operators for Json, enabling std::vector reallocations and parser insertions to move subtrees instead of deep-copying. Clean-room compliant. Approved.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6045185688 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1108#pullrequestreview-6045185688). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T18:38:36Z. **Review:** APPROVED --- Audited and verified. Removing the user-declared destructor allows the compiler to generate implicit move constructors and move assignment operators for Json, enabling std::vector reallocations and parser insertions to move subtrees instead of deep-copying. Clean-room compliant. Approved.
Deedlyy commented 2026-11-24 20:17:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Deedlyy on 2026-11-24T20:17:09Z.


Recommendation: [MERGE]

Reasoning: Removes Json's explicitly defaulted destructor so the implicit noexcept move constructor comes back, avoiding deep copies of parsed subtrees. One-line performance change with no behaviour change; shader_library_test and mods_test pass per the author. No new test, but none is really needed. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main. Merge once the queued checks are green.

Impact level: 2/10

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7143305612 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1108#issuecomment-7143305612). Originally posted by [Deedlyy](https://github.com/Deedlyy) on 2026-11-24T20:17:09Z. --- **Recommendation:** [MERGE] **Reasoning:** Removes `Json`'s explicitly defaulted destructor so the implicit noexcept move constructor comes back, avoiding deep copies of parsed subtrees. One-line performance change with no behaviour change; `shader_library_test` and `mods_test` pass per the author. No new test, but none is really needed. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with `main`. Merge once the queued checks are green. **Impact level:** 2/10
zmasi commented 2026-11-28 22:10:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T22:10:56Z.


Independent Verification Report — 269971a2bc + origin/main (c7753ed98a)

Environment: Windows 11 (26200), AMD Ryzen 9 5950X, MSVC 19.44.35228 (x64, /std:c++20 /EHsc /W4 /permissive- /utf-8, Debug /Od /MDd & Release /O2 /MD).
Verdict: PASS (Ready to merge) — clean Git merge with origin/main (aee1ef3e93b0) and combined Batch 11 set (6a93c1e1e828).

1. Red -> Green Type-Trait & MSVC STL Verification

  • Verified cleanly on MSVC 19.44 STL under both Debug (/Od /MDd, _ITERATOR_DEBUG_LEVEL=2) and Release (/O2 /MD) with std::vector<JsonObjectEntry> holding incomplete-at-declaration JsonObjectEntry elements:
    • Red (origin/main with user-declared ~Json()): std::is_nothrow_move_constructible_v<leonida::Json> == false and std::is_nothrow_move_assignable_v<leonida::Json> == false (std::move silently fell back to recursive deep-copying on every emplace_back and std::vector reallocation).
    • Green (269971a2bc): std::is_nothrow_move_constructible_v<leonida::Json> == true and std::is_nothrow_move_assignable_v<leonida::Json> == true; shader_library_test (Debug & Release) PASS.

2. Nested JSON Parse Throughput (500 parses of a 400-entry nested shader-index JSON document, MSVC /O2 /MD)

  • origin/main: 886.42 ms
  • 269971a2bc: 379.72 ms (2.33x faster with identical parsed AST).

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246553476 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1108#issuecomment-7246553476). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T22:10:56Z. --- ### Independent Verification Report — `269971a2bc` + `origin/main` (`c7753ed98a`) **Environment:** Windows 11 (`26200`), AMD Ryzen 9 5950X, MSVC `19.44.35228` (`x64`, `/std:c++20 /EHsc /W4 /permissive- /utf-8`, Debug `/Od /MDd` & Release `/O2 /MD`). **Verdict:** **PASS (Ready to merge)** — clean Git merge with `origin/main` (`aee1ef3e93b0`) and combined Batch 11 set (`6a93c1e1e828`). #### 1. Red -> Green Type-Trait & MSVC STL Verification - Verified cleanly on MSVC `19.44` STL under both Debug (`/Od /MDd`, `_ITERATOR_DEBUG_LEVEL=2`) and Release (`/O2 /MD`) with `std::vector<JsonObjectEntry>` holding incomplete-at-declaration `JsonObjectEntry` elements: - **Red (`origin/main` with user-declared `~Json()`):** `std::is_nothrow_move_constructible_v<leonida::Json> == false` and `std::is_nothrow_move_assignable_v<leonida::Json> == false` (`std::move` silently fell back to recursive deep-copying on every `emplace_back` and `std::vector` reallocation). - **Green (`269971a2bc`):** `std::is_nothrow_move_constructible_v<leonida::Json> == true` and `std::is_nothrow_move_assignable_v<leonida::Json> == true`; `shader_library_test` (Debug & Release) **PASS**. #### 2. Nested JSON Parse Throughput (`500` parses of a 400-entry nested shader-index JSON document, MSVC `/O2 /MD`) - `origin/main`: `886.42 ms` - `269971a2bc`: `379.72 ms` (**2.33x faster** with identical parsed AST). AI-assisted.
TheGeogeo commented 2026-11-29 02:17:13 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T02:17:13Z.


Tested 269971a2b merged (no commit) with main 53b77df14. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40, Windows 11 10.0.26300; MSVC 19.52 (Visual Studio 18), Ninja, RelWithDebInfo; Python 3.12.4. check_no_game_data.py is clean.

  • No test that tells the two apart: shader_library passes on main and on the merge (shader_library_corpus skips, since it needs a translated corpus).
  • No regression on MSVC: the merge rebuilds 183 executables, and of their 297 tests only xbox_present fails, as on plain main here.
  • LINK: gta6rt.exe links without ws2_32.lib with nothing new over main.

Risk to check before merging: the PR removes the out-of-line ~Json(). The comment it deletes explains that the out-of-line destructor is what lets Clang with libstdc++ build this header (pair<string, Json> as a vector element while Json is incomplete). I cannot check Clang here; the Linux/macOS CI jobs would show it. If the goal is the implicit moves, another way is to keep the out-of-line destructor and declare Json(Json&&) noexcept and operator=(Json&&) noexcept defaulted out of line too. Then a static_assert(std::is_nothrow_move_constructible_v<Json>) would be the test.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7249330350 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1108#issuecomment-7249330350). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T02:17:13Z. --- Tested `269971a2b` merged (no commit) with `main` `53b77df14`. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40, Windows 11 10.0.26300; MSVC 19.52 (Visual Studio 18), Ninja, RelWithDebInfo; Python 3.12.4. `check_no_game_data.py` is clean. - No test that tells the two apart: `shader_library` passes on `main` and on the merge (`shader_library_corpus` skips, since it needs a translated corpus). - No regression on MSVC: the merge rebuilds 183 executables, and of their 297 tests only `xbox_present` fails, as on plain `main` here. - LINK: `gta6rt.exe` links without `ws2_32.lib` with nothing new over `main`. **Risk to check before merging:** the PR removes the out-of-line `~Json()`. The comment it deletes explains that the out-of-line destructor is what lets Clang with libstdc++ build this header (`pair<string, Json>` as a vector element while `Json` is incomplete). I cannot check Clang here; the Linux/macOS CI jobs would show it. If the goal is the implicit moves, another way is to keep the out-of-line destructor and declare `Json(Json&&) noexcept` and `operator=(Json&&) noexcept` defaulted out of line too. Then a `static_assert(std::is_nothrow_move_constructible_v<Json>)` would be the test. AI-assisted (Claude Code).
TheGeogeo commented 2026-11-29 14:44:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T14:44:39Z.


Read at 269971a2b against main bd643e46e (diff reading, no new build). This answers the "no test" question.

  • A failing test is possible: static_assert(std::is_nothrow_move_constructible_v<leonida::Json>) in shader_library_test.cpp (the same for JsonObjectEntry).
    • On main it fails, because the user-declared ~Json() removes the implicit move constructor and the copy constructor is not noexcept.
    • With this PR it passes.
    • I did not compile it here.
  • The Clang/libstdc++ risk from my earlier comment still stands: the PR deletes the comment that explains why the destructor is out of line.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7257541685 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1108#issuecomment-7257541685). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T14:44:39Z. --- Read at 269971a2b against main bd643e46e (diff reading, no new build). This answers the "no test" question. - A failing test is possible: `static_assert(std::is_nothrow_move_constructible_v<leonida::Json>)` in `shader_library_test.cpp` (the same for `JsonObjectEntry`). - On main it fails, because the user-declared `~Json()` removes the implicit move constructor and the copy constructor is not `noexcept`. - With this PR it passes. - I did not compile it here. - The Clang/libstdc++ risk from my earlier comment still stands: the PR deletes the comment that explains why the destructor is out of line. AI-assisted (Claude Code).
aslan2142 commented 2026-12-01 10:37:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T10:37:46Z.

Review: APPROVED


Reviewed runtime/src/shader_library.h against current main: removing the user-declared ~Json() restores the implicitly declared noexcept move constructor and move assignment operator for Json and JsonObjectEntry, eliminating deep copies of nested JSON subtrees during std::vector growth/moves. Clean-room verified and merges cleanly.

Not merging immediately because the Nov 27 CI run shows unrelated stale-base failures in windows (vk_xdxr_postbuild_readback) and linux-gpu-tools (vk_null_descriptor_test). Ready to merge once CI is re-run green on current main (optionally adding a static_assert(std::is_nothrow_move_constructible_v<...>) guard in shader_library_test.cpp as suggested in the thread).

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6129565115 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1108#pullrequestreview-6129565115). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T10:37:46Z. **Review:** APPROVED --- Reviewed `runtime/src/shader_library.h` against current `main`: removing the user-declared `~Json()` restores the implicitly declared `noexcept` move constructor and move assignment operator for `Json` and `JsonObjectEntry`, eliminating deep copies of nested JSON subtrees during `std::vector` growth/moves. Clean-room verified and merges cleanly. Not merging immediately because the Nov 27 CI run shows unrelated stale-base failures in `windows` (`vk_xdxr_postbuild_readback`) and `linux-gpu-tools` (`vk_null_descriptor_test`). Ready to merge once CI is re-run green on current `main` (optionally adding a `static_assert(std::is_nothrow_move_constructible_v<...>)` guard in `shader_library_test.cpp` as suggested in the thread). *(AI-assisted review.)*
aslan2142 commented 2026-12-01 16:33:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:33:19Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317799380 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1108#issuecomment-7317799380). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:33:19Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1108
No description provided.