fix: 8 MB release stack (#223) + atomic telemetry call_count (#179)#236
Merged
fix: 8 MB release stack (#223) + atomic telemetry call_count (#179)#236
Conversation
ReleaseFast mainImpl only uses ~190 KB of stack (vs the ~33 MB in Debug builds). Reduce the trampoline thread stack to 8 MB in non-Debug modes so the 64 MB allocation no longer triggers Rosetta 2's protection fault on x86_64-macos (KERN_PROTECTION_FAILURE / SIGBUS / SIGILL). Fix the telemetry data race: call_count was a plain u32 mutated after write_lock was released. Change it to std.atomic.Value(u32) with a fetchAdd so concurrent record() calls have no undefined behaviour. Co-Authored-By: trilokagent <275208033+trilokagent@users.noreply.github.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
AnyTrigramIndex was refactored to a tagged union (heap/mmap/mmap_overlay) but approxIndexSizeBytes still accessed .index and .file_trigrams as direct fields, causing a compilation error. Switch on the union tag and iterate only for the .heap variant; mmap variants have no HashMap to walk. Co-Authored-By: trilokagent <275208033+trilokagent@users.noreply.github.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
64db291 to
7b3644c
Compare
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.
Summary
darwin-x86_64: startup crash under Rosetta on Apple Silicon #223 — Rosetta crash:
ReleaseFastmainImplonly uses ~190 KB of stack (verified viaotooldisassembly). The 64 MB trampoline thread was only needed in Debug builds where Zig merges branch frames into a large frame. Reduce to 8 MB for non-Debug builds — still 40× the actual need, well within Rosetta 2's limits. Fixes theKERN_PROTECTION_FAILURE/SIGBUS/SIGILLcrash oncodedb-darwin-x86_64under Rosetta.Bugs + improvements #179 (telemetry data race):
call_countwas a plainu32incremented afterwrite_lockwas released, making concurrentrecord()calls undefined behaviour. Changed tostd.atomic.Value(u32)withfetchAdd(.monotonic)— flush/syncToCloud stay outside the lock since they're slow I/O ops.Test plan
zig build testpasseszig build -Doptimize=ReleaseFast -Dtarget=x86_64-macossucceedsotoolconfirmsmain()stack frame is 80 bytes (trampoline overhead only),mainImplframe is ~190 KB — both well under 8 MBcodedb-darwin-x86_64 --versionsucceeds under Rosetta on Apple Silicon🤖 Generated with Claude Code