Skip to content

Conversation

@forketyfork
Copy link
Owner

@forketyfork forketyfork commented Jan 19, 2026

Summary

  • Add a generic metrics collection framework for monitoring glyph cache performance and frame rendering
  • New real-time overlay in top-right corner (toggle with Cmd+Shift+M when enabled)
  • Zero overhead when disabled - null pointer checks compile away, no allocations

Changes

  • src/metrics.zig: Core metrics module with enum-indexed fixed arrays for O(1) access
  • src/ui/components/metrics_overlay.zig: VTable UI component for overlay rendering
  • src/config.zig: Added [metrics] config section with enabled boolean
  • src/font.zig: Instrumented glyph cache hits/misses/evictions/size
  • src/main.zig: Frame count tracking, component registration, action handling
  • docs/: Updated configuration.md and architecture.md

Metrics tracked

  • glyph_cache_hits / glyph_cache_misses / glyph_cache_evictions / glyph_cache_size
  • frame_count

Configuration

[metrics]
enabled = false  # Toggle overlay with Cmd+Shift+M when enabled

Test plan

  • Build succeeds: zig build
  • Tests pass: zig build test
  • Start app with metrics.enabled = false → Cmd+Shift+M shows toast "Metrics disabled in config"
  • Start app with metrics.enabled = true → Cmd+Shift+M toggles overlay
  • Verify overlay shows updating rates during terminal activity
  • Verify no performance impact when disabled

Add a generic metrics collection framework for monitoring glyph cache
performance and frame rendering, controlled by config and toggled with
Cmd+Shift+M.

Key features:
- Zero overhead when disabled (null pointer checks compile away)
- Enum-indexed fixed arrays for O(1) access
- Tracks: glyph cache hits/misses/evictions/size, frame count
- Real-time overlay in top-right corner showing rates per second
- Follows existing VTable UI component pattern

Files added:
- src/metrics.zig: Core metrics module
- src/ui/components/metrics_overlay.zig: Overlay UI component

Configuration:
  [metrics]
  enabled = false  # Toggle with Cmd+Shift+M when enabled
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 52eef5dde3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@forketyfork forketyfork requested a review from Copilot January 19, 2026 08:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a lightweight, opt-in metrics collection system with a real-time overlay for monitoring glyph cache performance and frame rendering. The implementation is designed for zero overhead when disabled, using null pointer checks that compile away and avoiding allocations in the hot path.

Changes:

  • Added metrics collection framework with enum-indexed arrays for O(1) access to track glyph cache hits/misses/evictions/size and frame count
  • Implemented real-time overlay component (top-right corner) with Cmd+Shift+M toggle when enabled
  • Integrated metrics instrumentation into font glyph cache operations and main rendering loop

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/metrics.zig Core metrics module with Metrics struct, global pointer, and helper functions
src/ui/components/metrics_overlay.zig VTable-based UI component for rendering metrics overlay with texture caching
src/config.zig Added MetricsConfig struct with enabled boolean field
src/font.zig Instrumented glyph cache operations with metrics tracking
src/main.zig Initialize metrics storage, register overlay component, handle ToggleMetrics action
src/ui/types.zig Added ToggleMetrics action variant
src/ui/mod.zig Exported metrics_overlay module
src/c.zig Added SDLK_M constant for M key
docs/configuration.md Documented metrics configuration section and overlay usage
docs/architecture.md Updated architecture docs with metrics module and component

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

The keyboard shortcut handler was only emitting the action when metrics
were enabled, silently consuming the keystroke otherwise. Now the action
is always emitted so main.zig can show the "Metrics disabled" toast.

Also removed the unused metrics_enabled field from the component.
- Fix rate calculation bug: split sampleRates() into sampleRates() +
  commitSample() to avoid zeroing delta before getRate() is called
- Add error logging for action queue append instead of catch {}
- Strengthen catch rule in CLAUDE.md with explicit example

Addresses review comments on PR #141.
Add comment explaining why we use linear scan instead of LRU list:
the 4096-entry cache is large enough that evictions are rare in
practice, so simplicity wins over O(1) eviction complexity.
Prefix cache metrics with "Glyph" to distinguish from potential
future caches (e.g., texture cache, session cache). Display now
shows "Glyph cache:", "Glyph hits/s:", etc.
Derive frames-per-second from existing frame_count metric using
getRate(). No new instrumentation needed - just display the rate.
@forketyfork forketyfork merged commit f199efa into main Jan 19, 2026
4 checks passed
@forketyfork forketyfork deleted the metrics-framework branch January 19, 2026 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants