mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:10:51 +01:00
[PR #2031] runtime: harden submit_phases period parsing and skip Scope overhead when disabled #2038
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2038
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2031
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/rt-submit-phases-period-parse-and-zero-overhead-scope📝 Commits (1)
ed34b99runtime: harden submit_phases period parsing and skip Scope overhead when disabled📊 Changes
3 files changed (+133 additions, -10 deletions)
View changed files
📝
runtime/CMakeLists.txt(+3 -0)📝
runtime/src/submit_phases.h(+41 -10)➕
runtime/test/submit_phases_test.cpp(+89 -0)📄 Description
Coordination item:
RT-SUBMIT-PHASES-PERIOD-PARSE-AND-ZERO-OVERHEAD-SCOPE(claimed on #1608).Why
leonida::submit_phases::period_ns()parsedLEONIDA_SUBMIT_PHASES_SECONDSwithstd::strtoulland multipliedstd::int64_t(s) * 1000000000unchecked. A negative value like-1wrapped toUINT64_MAXand yieldedperiod_ns() == -1000000000, makingnow - last < periodpermanently false sosubmitted()printed tostderron every single submission; huge decimal strings triggered signed 64-bit overflow UB; non-numeric strings silently yielded0(disabling logging) instead of falling back to the 5 s default.submit_phases::Scopeunconditionally ran twosteady_clock::now()calls and two atomic RMWs (fetch_add+compare_exchange_weak) on every submission phase (wait_room,heaps,shadows,geometry,textures) even whenLEONIDA_SUBMIT_PHASES_SECONDS=0turned the periodic report off.add(Phase, ns)did not bounds-checkp < kCount,Scope::~Scope()castnow_ns() - startdirectly touint64_twithout guarding negative deltas, andprocess_age()subtractedFILETIMEticks without guarding clock step-back.Changes
runtime/src/submit_phases.h:parse_period_ns(const char*)that handles0(disable), positive decimal seconds with safe saturation atINT64_MAX / 1e9, and falls back to the 5 s default on null, empty, negative, or malformed input.steady_clock::now()andadd()insideScopewhenperiod_ns() <= 0, and guarddt > 0in~Scope().p >= kCountinadd(),period <= 0insubmitted(), andn >= cinprocess_age().runtime/test/submit_phases_test.cpp+runtime/CMakeLists.txt: add portable pure-stdlibsubmit_phasesCTest covering period parsing edge cases, saturation, accumulation, phase bounds, andScope/submitted().Verification
runtime/test/submit_phases_test.cppwithclang++ -std=c++20 -Wall -Wextra -Werror:-O1 -g -fsanitize=address,undefined, with unset,0, and-1):submit_phases_test: OK (0 failures).-O1 -g -fsanitize=thread):submit_phases_test: OK (0 failures).-O2):submit_phases_test: OK (0 failures).LEONIDA_SUBMIT_PHASES_SECONDS=-1):mainreturnedperiod_ns=-1000000000; this branch returnsperiod_ns=5000000000(5 s default).-O2benchmark (LEONIDA_SUBMIT_PHASES_SECONDS=0, 3,000,000Scopelifetimes):main:82.255 ms(ns_heaps=66940813)1.522 ms(ns_heaps=0, 54.04× faster, zero clock/atomic overhead when disabled).python3 -I scripts/check_no_game_data.py runtime/src/submit_phases.h runtime/test/submit_phases_test.cpp runtime/CMakeLists.txt: clean.python3 -I tests/test_text_write_line_endings.py: 3/3 OK.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.