Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .claude/agents/implementer.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ under the input-based Definition of done. Do not launch an independent full
pipeline at every handoff.

Report changed files, commands/results, meaningful deviations and anything left
undone. Commit, push or open a PR only when the user explicitly requests it.
undone. Commit verified task changes locally by default; push or open a PR only when the user explicitly requests it.
2 changes: 1 addition & 1 deletion .claude/skills/crate-split/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ when helpful. A crate-boundary change requires an ADR.
combined dependency changes settle. Use `gate` for both sides and consumers.
6. Review with `design-review`, fix findings and finish the applicable completion
checks. Report ownership/metric changes, checks/results and limitations.
Vendor and app changes require separate commits; commit/push/PR only on request.
Vendor and app changes require separate commits; commit verified task changes locally by default. Push/PR only on request.
5 changes: 5 additions & 0 deletions .claude/skills/design-review/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ and check the code against the authorized task.

## Ownership and cost

For every runtime-code change, apply the mandatory post-change
[performance review](../performance/SKILL.md) before approving the change.
Record its verdict and resolve blocking performance findings in this review;
routine bounded low-cost changes do not need separate benchmarks.

For changed state or boundaries, trace one actual use case through its owners:

- Who owns the authoritative state, its invariant and all transitions? Does the
Expand Down
2 changes: 1 addition & 1 deletion .claude/skills/feature/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ branch/base, plan/evidence location, scope and relevant prior findings.
input-based Definition of done after review fixes; preserve valid evidence.
6. Report what changed, commands/results, scope and remaining limitations.
Propose commit/PR text only when useful. Vendor and app changes belong in
separate commits; commit, push and PR actions require the user's request.
separate commits; commit verified task changes locally by default. Push and PR actions require the user's request.
6 changes: 4 additions & 2 deletions .claude/skills/gate/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ queuing the same pending check twice.

## Completion and failures

At integrated completion, choose the applicable AGENTS.md scope after review
At integrated completion, confirm the mandatory post-change
[performance review](../performance/SKILL.md) for runtime code has passed as
part of design review. Choose the applicable AGENTS.md scope after review
fixes. Broad shared changes, uncertain workspace impact or an explicit
full-verification request need the full workspace suite below. A small change
does not inherit that suite merely because a stage or worktree ended. Apply
Expand Down Expand Up @@ -96,7 +98,7 @@ Additional checks follow actual changed inputs:
- Hook changes run `python3 scripts/test-claude-hooks.py`; configuration-validator
changes run `python3 scripts/test-claude-config.py` as well.

Commit, push and PR creation still require the user's request.
Commit verified task changes locally without asking. Push and PR creation still require the user's request.

## Commands

Expand Down
68 changes: 65 additions & 3 deletions .claude/skills/performance/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,75 @@
---
name: performance
description: Evaluate changed hot paths, rendering, repeated I/O or caches using representative costs and behavior. Use for optimization work or changes that affect input latency, redraws, large collections, background jobs or retained memory; not as a benchmark gate for every edit.
description: Review performance of every coherent runtime-code change before commit. Trace execution frequency, CPU/GPU work, allocations, memory, latency, I/O and resource lifetime; prevent measured Nocterm regressions. Use relevant profiling and behavior evidence for hot paths; routine edits do not require a benchmark suite.
user-invocable: false
---

# Runtime cost and rendering

AGENTS.md's Performance rule applies. Keep notes and results in the existing
compact plan; this procedure creates no extra approval or completion stage.
AGENTS.md's Performance rule applies. Use this procedure both when designing
runtime code and after writing it: the post-change review is mandatory before
a local commit. Keep findings in the existing design review/compact plan; do
not create a parallel approval stage or run a full benchmark suite for routine
edits.

## Post-change review (always for runtime code)

1. Inspect task-related committed, staged, unstaged and relevant untracked
changes, not just the last edited file. Trace new/changed calls through real
producers, consumers, observers, lifetime and platform boundaries.
2. For every changed runtime path identify its trigger (one-shot, per item,
per event, per frame, periodic), maximum relevant size, multiplicative
fan-out and owner. Compare old and new work: algorithmic passes, allocations
and copied bytes, CPU/GPU operations, I/O, latency and retained resources.
Include no-change, idle, cancellation and large-input cases when applicable.
3. Apply the checklist below and read matching sections of
[review patterns](review-patterns.md) for concrete examples. A newly added
avoidable heavy operation in a frequent path, unbounded queue/cache/work,
or demonstrated regression is blocking; name the triggering workload and
smallest correction. Do not label a cheap bounded operation a blocker merely
because it has a theoretical alternative.
4. Fix blocking findings within the task, re-review the changed paths, and
obtain relevant behavior/cost evidence using the existing gate. For ordinary
low-cost paths a reasoned inspection is enough; for claimed speedups or
consequential changed hot paths use a representative measurement or report
precisely why it is unavailable. Never claim a measured improvement from
code inspection, a green test suite or FPS alone.

Record the outcome in the design review: inspected paths/triggers, workload
and expected or measured cost change, blocking findings/fixes, remaining
evidence limitations, and verdict (pass / changes required). If a change has
no runtime effect, state that briefly and stop this review.

## Checklist

- **Algorithm and allocation:** avoid repeated full collection traversals,
nested linear lookup, repeated normalization/serialization, large clones
before filtering, unnecessary intermediate strings/Vec/JSON values, and
allocating per item when existing borrowed slices, shared immutable data or
bounded scratch storage suffice. Preserve order, Unicode semantics, payload
bounds and checked mutations.
- **Rendering/GPU:** work proportional to the visible/changed region, not the
full catalog or history; avoid rebuilding unchanged view identities, text
shaping, image decode/upload, scene/buffer allocation or paint. Distinguish
layout, paint, submissions, actual GPU work and presentation. Do not cap
refresh or suppress valid frames to make a performance number look better.
- **Events and background work:** no unchanged-state notify, broad observer
fan-out, duplicate polling/subscriptions or timer wakeups in idle, hidden
or closed views. Scope updates to interested owners; coalesce only when
observable order, final state, feedback and cancellation remain correct.
- **I/O and concurrency:** no blocking I/O or heavy parsing on foreground
callbacks; avoid per-byte/row RPC, metadata query or process spawn. Batch
where semantics permit; bound queue count and bytes, worker concurrency,
retries, timeouts, and in-flight data. Do not trade responsiveness for
starvation or weaken durable write/admission/security contracts.
- **Memory/lifetime:** assess cumulative requested bytes separately from
retained memory and peak RSS/PSS; account for decoded pixels, GPU
VRAM/GTT, shared buffers, retained callbacks, clones and per-window/session
multiplication. Reclaim unused objects on close/cancel and handle late
results; avoid speculative caching or unbounded reuse buffers.
- **Evidence:** compare representative work across small/large, unchanged/
changed, warm/cold and loaded/idle conditions as appropriate. Verify exact
output, UI behavior, and other observable contracts before accepting wins.

## Find the cost

Expand Down
161 changes: 161 additions & 0 deletions .claude/skills/performance/review-patterns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Nocterm performance review patterns

Read the sections relevant to changed execution paths. These are lessons from
measured Nocterm optimization work, not rules that every code path must use
the same implementation. Prefer the simplest adequate change; preserve
behavior, layer ownership and lifetime. Reuse existing benchmark fixtures
rather than inventing duplicate harnesses.

## CPU, algorithms and allocation

**Trace cost multiplication.** A linear scan in a once-per-frame function
becomes expensive when repeated for every row, window, session or event.
Partition/group once, index repeated lookup at the existing owner when useful,
reuse prepared results on unchanged inputs, and check the worst supported
size. Preserve ordering, duplicates, identity, matching semantics and empty
results. Do not trade a small linear scan for an unnecessarily persistent
index. Connections/catalog reconciliation and workspace list projection
benefited from eliminating quadratic/repeated full scans. The cold Hub
mirror and detach fixtures in
[replication tests](../../../crates/connections-store/src/replication/tests/performance.rs)
exercise bulk and steady cases.

**Borrow or move before cloning.** Check what actually needs ownership.
Use slices/iterators/borrowed views, move already-owned values, share immutable
payloads where lifetimes justify it. Filter/select before cloning, format only
what is displayed or copied, avoid decoding/encoding the same JSON/text/image
for each consumer. Count calls and requested bytes, including deep nested
payloads; a cheap Arc clone is not a deep String/Vec clone. Avoid retaining a
huge source buffer just to save a tiny copy. If a payload can be locally
reused, bound the scratch capacity and lifecycle. Do not cache secrets.

**Skip work proven unnecessary, not merely unlikely.** Use an exact no-op
test or a necessary condition that cannot exclude a legitimate result.
Maintain Unicode, segmentation, error, boundary and ordering semantics.
The [redaction fixture](../../../crates/ai/src/redact.rs) measures ordinary,
sparse and dense matches and verifies the complete output. Reusing capture
storage and skipping provably irrelevant text reduced work without changing
the policy. This is not permission to weaken validation or security checks.
For specialized fast paths, characterize the fallback as well as the fast
case and compare against the actual previous behavior.

## Rendering and GPU

- Prepare stable model projections on source/query changes, consume them
during render; virtualize large lists using existing ListState/viewport
facilities. Render visible rows and bounded overscan, not every row.
Check variable heights, scroll anchors, focus/keyboard traversal,
accessibility, selection, filtering and action identity. The
[workspace fixture](../../../crates/projects/src/tests/library.rs) measures
large scroll and search with behavior assertions.
- Keep semantic state changes separate from focus, hover, animation and
geometry. A cursor blink or unchanged status must not rebuild a whole
transcript/catalog; an actual change must still invalidate the view.
Reuse stable identities rather than creating replacement entities and
subscriptions on redraw. Disable invisible animation only when its
lifecycle and visible behavior allow it. Do not reduce the refresh rate
or change animation duration merely to improve CPU numbers.
- Check for repeated text shaping/parsing, unused decoration geometry,
unnecessary image decode/resizing, texture uploads, buffers, layout
passes, hitboxes or scene copies. Preserve font/theme/scale, wrapping,
clipping, bidi, scroll and input behavior. Bound any reused buffer or
GPU resource by actual cost and dispose when its owner ends.
- Measure process/main-thread CPU, draw/submission work, actual device
graphics work and memory (including VRAM/GTT), plus operation-to-next
buffer latency. Samples from GPU timestamp queries describe the measured
encoder interval, not every GPU operation or input-to-photon.
A faster FPS counter with higher unnecessary work is not an optimization;
a lower FPS cap is not evidence of fewer operations for equivalent work.

## State, notifications and idle work

- Compare the relevant immutable snapshot/section or revision, not a full
unrelated document. Reuse unchanged results and suppress only equivalent
observable publications. Avoid rebuilding every consumer for one changed
row; retain identities and notify the exact affected owner. The
[settings tests](../../../crates/settings/src/store/tests.rs) measure
registered/snapshot costs; [layout publications](../../../crates/workspace/src/workspace/layout_switch_tests.rs)
exercise multi-window composition.
- Review callbacks for captured large data and stale references. Use narrow
IDs or shared immutable snapshots when safe; retain checked expected
records or revisions where needed for mutations. Freshness/authorization
remains with its original authoritative owner.
- One source can feed multiple active subscribers when semantics permit.
Stop polling, refresh timers and detached work when interest disappears;
bound necessary independent services. Verify both hidden/idle and active
states, and behavior after cancel/reopen. The Linux
[vault idle test](../../../crates/vault-store/tests/worker_idle.rs)
samples the worker's CPU time and context switches, not elapsed sleep
time. The [plugin-view handoff fixture](../../../crates/plugin-view/src/tests/performance.rs)
compares changed and equal views.

## I/O, transport and background work

- Count actual syscalls/metadata reads, RPCs, started processes, full-file
writes and user-visible round trips. Request only needed metadata/payload
and use existing projection/streaming ports. Prefer batching/pipelining
where ordering and error semantics permit, with bounded byte and request
budgets, backpressure and fair admission. Large transfers should not
starve terminal echo, input or discovery.
- Preserve durability and mutation semantics. A memory-only mirror is not
equivalent to a durable store; do not batch away required acknowledgements,
fsync or checked revisions to make a synthetic benchmark faster.
- Do not hold foreground/shared-state locks while doing expensive encoding,
filesystem, network or process I/O. Stage data through existing owners,
cancel obsolete work, validate the current scope before publication and
dispose of late results. Moving work to a background task does not remove
CPU, memory or scheduling cost.
- Test latency with real isolated local services where feasible, with
controlled delay and exact payload/operation outcomes. Measure both bulk
throughput and interactive latency under concurrent load. The
[SSH performance fixtures](../../../crates/ssh/tests/cases/performance.rs)
include controlled-latency SFTP and terminal echo. Never target real
accounts or servers without authorization.

## Memory and lifetime

Distinguish requested allocation traffic, successful allocation calls,
peak RSS, PSS/anonymous PSS, retained heap, mapped/shared pages and GPU
residency. They answer different questions. Account for data growth across
windows, sessions, history, scrollback, plugin instances, observers and
decoded images. An optimization can reduce allocation traffic while keeping
resident memory unchanged or increasing retained buffers; measure the
tradeoff. Check teardown and repeated open/close and large-to-small changes.
The [VT selection fixtures](../../../crates/vt/tests/selection_cost.rs)
check history sizes/widths and exact copied content rather than assuming
that shorter retained text implies lower memory.

## Choose defensible measurements

1. Name the operation, owner, input shape and exact completion boundary;
measure frequency × work and the caller-visible output. A producer
finishing does not prove its consumer, rendering or durable write finished.
2. Use optimized/release builds with comparable settings, workload, input
count, size, display cadence, device/backend and initial state. Compare
old/new in repeated alternating runs (ABBA when appropriate), separate
cold/warm/unchanged/changed paths. Report p50/p95 or distributions for
latency, and absolute work per operation/interval. Short microbenchmarks
need enough repetitions and realistic controls to reveal regressions.
3. Pick counters for the cost under investigation: CPU scheduled time,
instructions/cycles, allocation count/requested bytes, memory residency,
GPU work, calls/bytes/I/O or latency. Use separate profiling lanes where
tracing, sampling, allocation interception or GPU queries perturb timing.
Identify scope: app, thread, whole process tree or server. Single-core
pinning is a stress/control for concurrent workloads, not multicore
latency; do not confuse wrapper or child measurements with app-only cost.
4. Verify the same complete output and visible behavior (exact buffers,
render/crop comparisons excluding only explained dynamic regions,
selection/focus and cancellation). Check that the intended fixture
actually executed and did not skip due to an unavailable service.
5. Reuse the repository's [performance harness](../../../scripts/perf/README.md)
and existing manual fixtures. Isolate user data, processes, profiles and
compositor; do not alter the installed application or user's display.
If only a virtual compositor or partial platform is available, identify
that limitation. Do not claim physical scanout, other OS/device, or
real-world WAN results from the isolated test.

For automated regression gates, prefer deterministic assertions about
observable operation counts, byte/queue budgets, unchanged publications,
exact output and lifecycle. Manual performance fixtures may report timing
and counters; avoid fragile wall-clock thresholds in ordinary CI. Record
actual evidence and regression tradeoffs, not a universal speedup.
Loading
Loading