Make peak-memory tracking a compile-time option (SP_TRACK_MEMORY) - #118
Merged
Conversation
The sp_malloc/sp_free counters g_allocated_bytes and g_peak_bytes were the only mutable global state in the library, and every allocation updated them without synchronization. They feed nothing but the "Peak memory" line in the verbose problem summary. Gate them behind a CMake option, SP_TRACK_MEMORY, default OFF. In the default build the sp_* wrappers are plain malloc/calloc/realloc/free and the globals do not exist, so the library carries no shared state and is safe to use from multiple threads as long as each expression tree is touched by one thread. Verbose output prints "n/a" for peak memory unless built with -DSP_TRACK_MEMORY=ON. Stays on C99. Alternative to #100, which used _Thread_local and required C11. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FbYHhSoJ1BpEohQrjhdrG7
With SP_TRACK_MEMORY off the verbose summary now simply omits the peak memory line. Also reformat permuted_dense_linalg.c, which was failing the clang-format CI check on main. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FbYHhSoJ1BpEohQrjhdrG7
dance858
added a commit
that referenced
this pull request
Sep 5, 2026
…CK_MEMORY Resolve the test_matmul_dispatchers.h conflict by keeping both #115's transpose-cache test and the branch's BTDA no-transient-alloc test. #118 made g_allocated_bytes / g_peak_bytes exist only under SP_TRACK_MEMORY, so the no-alloc test (which reads those counters) and its registration are now wrapped in #ifdef SP_TRACK_MEMORY. Default build: 448 tests pass; -DSP_TRACK_MEMORY=ON: 449 tests pass. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016ATepXjts1gBX485mSguzk
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Put peak memory behind a development flag so library can be called from multiple threads at the same time without race conflicts in production.