Skip to content

Deep hot-path optimizations: zero-allocation steady-state draw path#489

Merged
Krilliac merged 1 commit into
Workingfrom
claude/deep-project-optimizations-b6cCt
Apr 17, 2026
Merged

Deep hot-path optimizations: zero-allocation steady-state draw path#489
Krilliac merged 1 commit into
Workingfrom
claude/deep-project-optimizations-b6cCt

Conversation

@Krilliac

Copy link
Copy Markdown
Owner

Five targeted micro-optimizations across rendering, ECS, and asset subsystems, each verified against the full 5867-test suite.

  1. Utils/Hash.h: add TransparentStringHash + TransparentStringEqual (is_transparent, std::hash<string_view>-backed) for heterogeneous unordered_map lookup by string_view/const char*.

  2. AssetPipeline::m_assets switches to transparent hashing. BindMesh / BindMaterial now accept std::string_view, eliminating a pair of std::string allocations per draw call in GraphicsEngine::ProcessDrawList.

  3. GraphicsEngine::ProcessDrawList double-buffers via std::swap against a new persistent m_processingDrawList. Previously std::move dropped capacity and reserve() reallocated each frame; now zero heap activity on the draw-list management path in steady state.

  4. SpriteAnimatorSystem: hoist clip->frames.size() out of the per-entity inner loop (four repeated size+cast probes collapse to one).

  5. MaterialSystem::m_materials and m_textureCache adopt transparent hashing for the same reason as AssetPipeline::m_assets — internal lookups and future string_view callers no longer allocate.

Deferred as out-of-scope: camera mutex->atomic (thread-model change), lock-free asset queue (rearchitecture), std::function->template callbacks (API churn), MaterialPropertyHandle LRU (no profiling evidence).

All 5867 tests pass. Documented in .claude/knowledge/deep-optimizations-2026-04-17.md.

https://claude.ai/code/session_01NJoVwD2TUCvaHoXJS6fkrR

Five targeted micro-optimizations across rendering, ECS, and asset
subsystems, each verified against the full 5867-test suite.

1. Utils/Hash.h: add TransparentStringHash + TransparentStringEqual
   (is_transparent, std::hash<string_view>-backed) for heterogeneous
   unordered_map lookup by string_view/const char*.

2. AssetPipeline::m_assets switches to transparent hashing. BindMesh /
   BindMaterial now accept std::string_view, eliminating a pair of
   std::string allocations per draw call in GraphicsEngine::ProcessDrawList.

3. GraphicsEngine::ProcessDrawList double-buffers via std::swap against a
   new persistent m_processingDrawList. Previously std::move dropped
   capacity and reserve() reallocated each frame; now zero heap activity
   on the draw-list management path in steady state.

4. SpriteAnimatorSystem: hoist clip->frames.size() out of the per-entity
   inner loop (four repeated size+cast probes collapse to one).

5. MaterialSystem::m_materials and m_textureCache adopt transparent
   hashing for the same reason as AssetPipeline::m_assets — internal
   lookups and future string_view callers no longer allocate.

Deferred as out-of-scope: camera mutex->atomic (thread-model change),
lock-free asset queue (rearchitecture), std::function->template callbacks
(API churn), MaterialPropertyHandle LRU (no profiling evidence).

All 5867 tests pass. Documented in .claude/knowledge/deep-optimizations-2026-04-17.md.

https://claude.ai/code/session_01NJoVwD2TUCvaHoXJS6fkrR
@Krilliac
Krilliac merged commit de3e8b9 into Working Apr 17, 2026
33 of 41 checks passed
@Krilliac
Krilliac deleted the claude/deep-project-optimizations-b6cCt branch April 17, 2026 18:14
@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage (GCC + lcov)

Utils/Result.h                                 | 100%    29| 0.0%  28|    -    0
Utils/RingBuffer.h                             | 142%    59| 0.0%  84|    -    0
Utils/ScheduledCallback.h                      |    -     0|    -   0|    -    0
Utils/ScopeGuard.h                             | 142%    36| 0.0%  51|    -    0
Utils/ScopedTimer.h                            |25.0%    12| 0.0%   3|    -    0
Utils/Serializer.h                             |86.2%    58| 0.0%  44|    -    0
Utils/ShaderServiceClient.cpp                  |12.2%    41| 0.0%   4|    -    0
Utils/ShaderServiceClient.h                    | 100%     1| 0.0%   1|    -    0
Utils/ShaderServiceProtocol.h                  |11.8%    68| 0.0%   8|    -    0
Utils/SparkConsole.cpp                         |27.2%   151| 0.0%  18|    -    0
Utils/SparkConsole.h                           | 100%     2| 0.0%   2|    -    0
Utils/SparkError.h                             |10.9%    55| 0.0%   6|    -    0
Utils/SplineMath.cpp                           |20.5%    39| 0.0%   5|    -    0
Utils/SplinePath.h                             |    -     0|    -   0|    -    0
Utils/StackTrace.h                             |10.8%    74| 0.0%   8|    -    0
Utils/StateMachine.h                           |85.9%    64| 0.0%  49|    -    0
Utils/StringUtils.h                            |18.1%   116| 0.0%  21|    -    0
Utils/Telemetry.h                              |20.6%   136| 0.0%  23|    -    0
Utils/ThreadDebugger.h                         |11.6%   199| 0.0%  23|    -    0
Utils/ThreadSafeQueue.h                        |27.5%    40| 0.0%  11|    -    0
Utils/Timer.cpp                                |19.4%    36| 0.0%   7|    -    0
Utils/Timer.h                                  | 100%     2| 0.0%   2|    -    0
Utils/TimerManager.h                           |18.6%   102| 0.0%  19|    -    0
Utils/Tween.h                                  |26.3%    38| 0.0%   6|    -    0
Utils/UUID.h                                   |43.2%    37| 0.0%  16|    -    0
Utils/Validate.h                               |    -     0|    -   0|    -    0
Utils/WineDetection.cpp                        |23.1%    39| 0.0%   9|    -    0

[/home/runner/work/SparkEngine/SparkEngine/SparkSDK/Include/Spark/]
IEngineContext.h                               |7300%     1| 0.0%   1|    -    0
ServiceInterfaces.h                            | 200%     3| 0.0%   3|    -    0
Version.h                                      |    -     0|    -   0|    -    0
================================================================================
                                         Total:|31.0% 34128| 0.0%  6k|    -    0

Per-Subsystem Coverage

Subsystem Lines Hit Coverage Threshold Status
AI 3716 942 25.3% 35%
Animation 905 277 30.6% 35%
Audio 0 0 0% 30%
Camera 0 0 0% 40%
Core 4882 2918 59.8% 40%
ECS 426 213 50% 40%
Editor 7411 3046 41.1% 25%
GameModules 6621 3230 48.8% 30%
Graphics 17004 8336 49% 30%
Networking 3554 2351 66.2% 35%
Physics 0 0 0% 35%
Scripting 283 80 28.3% 30%
Utils 9778 6050 61.9% 60%

Total: 50.3% (27443/54580 lines)

@github-actions

Copy link
Copy Markdown
Contributor

❌ CI Error Report

Failed jobs: check-format, clang-tidy, linux-clang-Release, macos-Debug, macos-Release, windows-vs2022-Release
Errors: 3 | Test failures: 4 | Test warnings: 15 | Compiler warnings: 6

Build Errors

File Line Error Jobs
SparkEngine/Source/Utils/Expected.h 40 code should be clang-formatted [-Wclang-format-violations] check-format
Other errors (2)
clang++: error: linker command failed with exit code 1 (use -v to see invocation) [linux-clang-Release]
clang++: error: linker command failed with exit code 1 (u e -v to  ee invocation) [macos-Debug, macos-Release]
Full error output
SparkEngine/Source/Utils/Expected.h:40:31: error: code should be clang-formatted [-Wclang-format-violations]
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
clang++: error: linker command failed with exit code 1 (u e -v to  ee invocation)
### Test Failures
Test Jobs
1/1 Test #1: SparkEngineTests .................***Failed 14.54 sec windows-vs2022-Release
[ FAILED ] NetworkStack_UDPInitializeSucceeds (127us, 3 assertions) windows-vs2022-Release
::warning title=Flaky test: Integration_NetworkingECS_ReplicationLatencyJitterPredictionReconciliation::Integration_N... windows-vs2022-Release
0% tests passed, 1 tests failed out of 1 windows-vs2022-Release

⚠️ Test Warnings (Known Flaky)

These tests are registered as known flaky and do not block the build:

Test Jobs
[18:51:20.032] [TID:3028] [WARN ] [Network ] RCON unknown command: nonexistent_cmd (DedicatedServer.cpp:573) windows-vs2022-Release
[18:51:20.051] [TID:3028] [WARN ] [Network ] NetBuffer::ReadUint8 — buffer overrun at pos 1 (size=1) (NetworkBuffer.c... windows-vs2022-Release
[18:51:20.074] [TID:3028] [WARN ] [AI ] BuildNavMeshWithRecast: empty geometry (RecastDetourBackend.cpp:35) windows-vs2022-Release
[18:51:20.074] [TID:3028] [WARN ] [AI ] NavMeshBuilder: Recast build failed, falling back to triangle-soup builder (N... windows-vs2022-Release
[18:51:20.075] [TID:3028] [WARN ] [AI ] NavMeshBuilder: Recast build failed, falling back to triangle-soup builder (N... windows-vs2022-Release
[18:51:20.075] [TID:3028] [WARN ] [Audio ] XAudio2 backend requested but no AudioEngine provided, falling back to Nul... windows-vs2022-Release
[ OK ] NullRHIDevice_ReinitializeAfterShutdown (0us, 5 asse[18:51:20.077] [TID:3028] [WARN ] [Graphics ] No graphics ... windows-vs2022-Release
[18:51:20.077] [TID:3028] [WARN ] [Graphics ] No graphics backend available — falling back to NullRHIDevice (headless... windows-vs2022-Release
[18:51:20.082] [TID:3028] [WARN ] [Editor ] Cannot host: userName is empty. (CollaborativeEditSession.cpp:454) windows-vs2022-Release
[18:51:20.082] [TID:3028] [WARN ] [Editor ] Already connected. (CollaborativeEditSession.cpp:459) windows-vs2022-Release
[18:51:20.085] [TID:3028] [WARN ] [Editor ] BroadcastEdit rejected: nodeId is empty. (CollaborativeEditSession.cpp:1108) windows-vs2022-Release
[18:51:20.085] [TID:3028] [WARN ] [Editor ] BroadcastEdit rejected: sourceEditor is not set. (CollaborativeEditSessio... windows-vs2022-Release
[18:51:20.086] [TID:3028] [WARN ] [Editor ] SetLocalSelection rejected: nodeId exceeds 255 chars (length=300). (Colla... windows-vs2022-Release
[18:51:25.646] [TID:3028] [WARN ] [Network ] Connection rejected for pending client 5: server full (4/4) (NetworkConn... windows-vs2022-Release
[18:51:25.647] [TID:3028] [WARN ] [Network ] Connection rejected for pending client 5: server full (4/4) (NetworkConn... windows-vs2022-Release
Compiler Warnings (6)
../../../ThirdParty/SDL2/src/joystick/hidapi/SDL_hidapi_steam.c:165:9: warning: 'printf' macro redefined [-Wmacro-redefined] [linux-clang-Release]
../SparkEngine/Source/Engine/Animation/BlendSpace.cpp:313:16: warning: variable 'validTriCount' set but not used [-Wunused-but-set-variable] [linux-clang-Release]
../SparkEngine/Source/Physics/PhysicsBodyImpl.cpp:270:23: warning: comparing floating point with == or != is unsafe [-Wfloat-equal] [linux-clang-Release]
../SparkEngine/Source/Physics/PhysicsSystem.cpp:401:12: warning: use of old-style cast [-Wold-style-cast] [linux-clang-Release]
../../Tests/TestReliableChannel.cpp:390:9: warning: variable 'retransmitCount' set but not used [-Wunused-but-set-variable] [linux-clang-Release]
../../Tests/TestSparkError.cpp:34:5: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result] [linux-clang-Release]

Updated: 2026-04-17T19:02:51Z — this comment is updated in-place, not duplicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants