Skip to content

refactor(runtime): key window demand counters by enum - #506

Merged
eval-exec merged 1 commit into
mainfrom
refactor/window-demand-enum-map
Oct 8, 2026
Merged

eval-exec merged 1 commit into
mainfrom
refactor/window-demand-enum-map

Conversation

@eval-exec

Copy link
Copy Markdown
Owner

Per-window frame-demand counters used a positional array and required converting DemandReason to an integer index on each update. Store them as EnumMap<DemandReason, u64> and index directly with the reason.

Derive enum_map::Enum on the existing enum. Default new windows to zero counters, retain counts during demand reconciliation, and convert to the existing fixed-size array only when producing diagnostic snapshots. Keep the public snapshot fields, reason names, ordering, and process-wide atomic counters unchanged.

Add enum-map 3.1.0 and enum-map-derive 1.0.1. The derive crate requires proc-macro2 1.0.107 and quote 1.0.47, updating those two locked patch versions; other existing package versions are unchanged.

Validation: cargo nextest run -p neomacs-display-runtime --lib -E 'test(render_thread::frame_sched::frame_sched_test::)' passes all 46 scheduler tests in parallel. An added regression test assigns a distinct count to every reason and verifies zero initialization, diagnostic array/name alignment, count retention during reconciliation, and removal of window stats. Formatting and diff checks pass. Tests remain in render_thread/tests/frame_sched_test.rs.

Copilot AI balanced review requested due to automatic review settings October 8, 2026 02:02
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2c40daf8-6b23-4f44-9581-396cbb0cf3fc
📥 Commits

Reviewing files that changed from the base of the PR and between 8d0bd5a and 0090805.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • Cargo.toml
  • crates/neomacs-display-runtime/Cargo.toml
  • crates/neomacs-display-runtime/src/render_thread/frame_sched.rs
  • crates/neomacs-display-runtime/src/render_thread/frame_stats.rs
  • crates/neomacs-display-runtime/src/render_thread/tests/frame_sched_test.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Per-window demand-plan counters now use EnumMap keyed by DemandReason. Snapshot output remains array-shaped. A new test checks counter order, retention after clearing active reasons, and removal when a window is withdrawn.

Changes

Demand reason counters

Layer / File(s) Summary
Key counters by demand reason
Cargo.toml, crates/neomacs-display-runtime/Cargo.toml, crates/neomacs-display-runtime/src/render_thread/frame_sched.rs, crates/neomacs-display-runtime/src/render_thread/frame_stats.rs, crates/neomacs-display-runtime/src/render_thread/tests/frame_sched_test.rs
The runtime adds enum-map and derives Enum for DemandReason. Per-window plan counts use EnumMap, while snapshots retain their array shape. The added test checks diagnostic ordering, count retention, and snapshot removal.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to 00908

No actionable merge-blocking risk is identified; the change is ready for normal merge checks.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main refactor: replacing positional window demand counters with enum-keyed counters.
Description check ✅ Passed The description directly explains the counter refactor, dependency updates, preserved behavior, regression test, and validation results.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. (2 skipped: 2 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The change is correct and well-tested, but it adds a new third-party dependency (and a second major version of syn to the tree), which is a supply-chain/dependency-policy decision warranting human sign-off.

0 open findings

What changed in this PR

This PR is a focused ergonomic refactor of per-window frame-demand attribution in the render-thread scheduler. It replaces the positional [u64; DemandReason::COUNT] plan counter, which required converting each DemandReason to an integer index on every update, with an EnumMap<DemandReason, u64> indexed directly by the reason. The public diagnostic snapshot shape (WindowFrameSnapshot.demand_reasons, reason names, ordering) and process-wide atomic counters are intentionally preserved, so downstream consumers are unaffected.

Changes:

  • Derive enum_map::Enum on DemandReason and store per-window plans as EnumMap<DemandReason, u64>, indexing with the reason directly and converting to the fixed-size array only for diagnostic snapshots.
  • Add a regression test covering zero-initialization, diagnostic array/name alignment, count retention across demand reconciliation, and window-stats removal.
  • Add the enum-map 3.1.0 / enum-map-derive 1.0.1 dependencies (with corresponding proc-macro2/quote patch bumps and syn 3.0.4 in the lockfile).
File Description
crates/​neomacs-display-runtime/​src/​render_thread/​frame_sched.rs Adds enum_map::Enum to the DemandReason derive list in the defining macro.
crates/​neomacs-display-runtime/​src/​render_thread/​frame_stats.rs Switches the per-window plans field to EnumMap, using reason-keyed indexing, default(), and into_array() for snapshots.
crates/​neomacs-display-runtime/​src/​render_thread/​tests/​frame_sched_test.rs New test validating zero-init, ordering, count retention, and removal of window demand stats.
crates/​neomacs-display-runtime/​Cargo.toml Adds the enum-map workspace dependency to the crate.
Cargo.toml Declares enum-map = "3.1.0" in the workspace dependency table.
Cargo.lock Locks enum-map/enum-map-derive and the induced proc-macro2/quote/syn version updates.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@eval-exec
eval-exec merged commit 8af179f into main Oct 8, 2026
30 of 43 checks passed
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