feat(memory): TraceSink API — one event stream for phases, kernels, adapters, allocations, counters and plans (SKEEP-003 P2, S1.5) - #1061
Merged
Conversation
…dapters, allocations, counters and plans (SKEEP-003 P2) Milestone M1 (#1002), PRD M1-F7 (API half; exporters follow in #1025). - sk.ainet.lang.memory.trace.TraceEvent (sealed): PhaseBegin/PhaseEnd (load · compile · prefill · decode(step) · module spans), KernelRun (op, kernel key, input/output TensorIds, bytes read/written, duration), AdapterInserted (kind, from/to Format, bytes, target, scope), Allocation / Free (storageId, ScopeKind, bytes, origin TensorId, debug site), ScopeReset (live bytes before/after), Counter (platform samples), Plan (the M0 MemoryPlan, for the plan-vs-actual check #1030). TraceClock: monotonic nanoseconds. - TraceSink (isEnabled + emit), NoopTraceSink (the default: one check, no allocation), RecordingTraceSink (ring buffer with emitted/dropped counters; the debugger, tests and #1030 read it), CompositeTraceSink; inline helpers TraceSink.phase { } and TraceSink.kernel { } that short-circuit when disabled and time the block; MemoryPlan.emit(sink). - ExecutionContext.traceSink: default member returning NoopTraceSink — opt-in per context, no change for existing implementations. - TraceSinkTest (ring buffer, ordering, phase/kernel helpers incl. exception path, identity fields on events, composite fan-out, plan event, clock). BCV dumps regenerated (lang-core, backend-cpu, compile-dag gain the inherited getTraceSink()). Closes #1017 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ageId, StorageClosedException, Heap on every target (SKEEP-003 P2) Milestone M1 (#1002), PRD M1-F1 (core). SKEEP-003 §4.2–4.4, rules 1–2: exactly one byte owner; ownership is a constructor argument and then enforced. - sk.ainet.lang.memory.Storage (sealed, AutoCloseable): id, sizeBytes, owner, domain, scope (from the owner), debugOrigin TensorId, isAlive, isMutable, checkAlive() → StorageClosedException(id, origin), close() (idempotent; owned = freed once, borrowed = forgotten, alias = detached; emits TraceEvent.Free), slice() → Owner.Alias view that keeps the parent alive, delegates mutability and dies with it. Kinds: Heap (final, common), OffHeap / Mapped / Device (abstract, bound per platform in #1019/#1020; Device is a placeholder). - Storage.Heap: one Kotlin array (floats | ints | bytes) + arrayOffset + sizeBytes; floats()/ints()/bytes() allocate owned storage for a scope kind and emit TraceEvent.Allocation; wrap(array, …) borrows without copying (the #782 copyOf replacement) and is never freed by us. Kernels unwrap once per call (floats/ints/bytes + arrayOffset), per the Phase-2 spike (#1016). - Owner (sealed): Owned(scope) | Borrowed(external) | Alias(parent). StorageId: monotonic per-process value class (kotlin.concurrent.atomics). MemoryDomain gains HOST_OFFHEAP (additive). - StorageTest: owned lifecycle + trace events, ids, borrowed release without touching the lender's bytes, alias lifetime/mutability/ nesting, slice bounds/alignment, rendering. BCV: lang-core jvm dump regenerated (additions only). Closes #1018 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Author
|
Local gate Targeted: lang-core |
|
📖 Documentation Preview The documentation has been built successfully for this PR. Generated Files:
Artifacts:
This comment will be updated automatically when the PR is updated. |
…-common-heap feat(memory): Storage — the one byte owner: sealed kinds, Owner, StorageId, StorageClosedException, Heap on every target (SKEEP-003 P2, S1.1a)
|
📖 Documentation Preview The documentation has been built successfully for this PR. Generated Files:
Artifacts:
This comment will be updated automatically when the PR is updated. |
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
SKEEP-003 slice S1.5 (milestone M1 #1002, PRD M1-F7 — API half; the Perfetto / JFR /
android.os.Traceexporters follow in #1025):TraceSink, the one event stream that stage-performance measurement, allocation tracking and the debugger surfaces consume (§4.9).sk.ainet.lang.memory.trace.TraceEvent(sealed, opt-in@ExperimentalMemoryApi):PhaseBegin/PhaseEnd(load·compile·prefill·decode(step)· module spans),KernelRun(op, kernel key, input/outputTensorIds, bytes read/written, duration),AdapterInserted(kind, from/toFormat, bytes, target, scope — the "hidden 12 GB" of GGUF DEQUANTIZE_TO_FP32 over-allocates: 1.1B Q4_K_M needs >12 GB heap transiently (~4.4 GB legit) #782 becomes visible),Allocation/Free(storage id,ScopeKind, bytes, originTensorId, debug site),ScopeReset,Counter,Plan(the M0MemoryPlan, for the plan-vs-actual check [S1.9] M1: plan-vs-actual — allocation-event totals vsMemoryPlan, printed; CI assertion (> 10 % fails) #1030).TraceClock= monotonic nanoseconds.TraceSink(isEnabled+emit),NoopTraceSink(default — one check, no allocation),RecordingTraceSink(ring buffer withemitted/droppedcounters),CompositeTraceSink; inline helpersTraceSink.phase { }andTraceSink.kernel { }that short-circuit when disabled and time the block (also on exception);MemoryPlan.emit(sink).ExecutionContext.traceSinkdefault member →NoopTraceSink; opt-in per context, no change for existing implementations.TraceSinkTest(ring capacity/order, helpers incl. the exception path, identity fields, composite fan-out, plan event, clock). BCV dumps regenerated — lang-core, backend-cpu, compile-dag gain the inheritedgetTraceSink(); additions only.Lands before the
Storageslices (#1018…) so allocation events exist from the firstStorage.allocate.Test plan
Full local gate (
scripts/pr-gate.sh, JDK 25); results in the first comment. Targeted: lang-coresk.ainet.lang.memory.*30/30.Closes #1017
🤖 Generated with Claude Code