-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add metrics collection framework with real-time overlay #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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
There was a problem hiding this 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".
There was a problem hiding this 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.
Summary
Changes
[metrics]config section withenabledbooleanMetrics tracked
glyph_cache_hits/glyph_cache_misses/glyph_cache_evictions/glyph_cache_sizeframe_countConfiguration
Test plan
zig buildzig build testmetrics.enabled = false→ Cmd+Shift+M shows toast "Metrics disabled in config"metrics.enabled = true→ Cmd+Shift+M toggles overlay