Skip to content

refactor(renderer): replace WeakMap theme propagation with stack#211

Merged
RtlZeroMemory merged 2 commits intomainfrom
perf/ink-compat-optimized-renderer
Feb 26, 2026
Merged

refactor(renderer): replace WeakMap theme propagation with stack#211
RtlZeroMemory merged 2 commits intomainfrom
perf/ink-compat-optimized-renderer

Conversation

@RtlZeroMemory
Copy link
Owner

@RtlZeroMemory RtlZeroMemory commented Feb 26, 2026

Summary

  • remove WeakMap<RuntimeInstance, Theme> theme propagation in renderTree()
  • add a stack-aligned themeStack parallel to nodeStack/styleStack/layoutStack/clipStack
  • preserve traversal order and theme override semantics for themed, row, column, grid, and box

Perf rationale

Removed WeakMap from hot loop; replaced with stack; semantics preserved.

Validation

  • cd /home/k3nig/Rezi && npm test
  • node --import tsx --test --test-concurrency=1 packages/core/src/renderer/__tests__/render.golden.test.ts packages/core/src/renderer/__tests__/spinner.golden.test.ts

Summary by CodeRabbit

  • Refactor

    • Optimized internal theme propagation to improve efficiency while preserving existing theming behavior.
  • Chores

    • Improved build compatibility with MSVC toolchains for more reliable compilation on Windows.
    • Updated a bundled third‑party library reference to a newer commit.

@coderabbitai
Copy link

coderabbitai bot commented Feb 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 926fd75 and da8fd8c.

📒 Files selected for processing (2)
  • packages/native/vendor/zireael/src/util/zr_macros.h
  • vendor/zireael
✅ Files skipped from review due to trivial changes (1)
  • vendor/zireael

📝 Walkthrough

Walkthrough

Replaces per-node WeakMap theme tracking in renderTree.ts with a stack-based themeStack approach; computes current theme from the stack and propagates each node's renderTheme to its children via batch pushes. Also adds an MSVC-specific branch for ZR_ARRAYLEN in zr_macros.h and updates the zireael submodule reference.

Changes

Cohort / File(s) Summary
Theme Stack Refactoring
packages/core/src/renderer/renderToDrawlist/renderTree.ts
Replaces per-node WeakMap (themeByNode) with a themeStack mechanism. currentTheme is derived from the stack; node renderTheme is computed and batch-pushed to children using a nodeStackLenBeforePush boundary to ensure correct propagation. Control flow reordered to compute theme early.
MSVC-safe array-length macro
packages/native/vendor/zireael/src/util/zr_macros.h
Introduces an MSVC-specific branch for ZR_ARRAYLEN(arr) guarded by #if defined(_MSC_VER) && !defined(__clang__), using sizeof(arr)/sizeof((arr)[0]) on MSVC and retaining the GNU-builtins/type-checking form elsewhere; adds explanatory comment.
Vendor submodule bump
vendor/zireael
Updated submodule reference from commit f60ffe78... to 435d28bc... (submodule pointer change only).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through stacks of themes and code,
I pushed, I popped, down every node.
A macro tweaked for MSVC's frame,
A submodule pin, a tiny name.
Hooray — the render's snug and prim! 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: replacing WeakMap-based theme propagation with a stack-based mechanism in the renderer, which is the primary focus of the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch perf/ink-compat-optimized-renderer

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/core/src/renderer/renderToDrawlist/renderTree.ts (1)

128-128: Add a dev guard for theme stack underflow on Line 128.

themeStack.pop() ?? theme silently falls back if stack alignment breaks, which can hide traversal bugs and produce hard-to-debug theming drift.

Suggested hardening
-    const currentTheme = themeStack.pop() ?? theme;
+    const poppedTheme = themeStack.pop();
+    if (DEV_MODE && poppedTheme === undefined) {
+      warnDev("[rezi][render] theme stack underflow; falling back to root theme.");
+    }
+    const currentTheme = poppedTheme ?? theme;

As per coding guidelines, all TypeScript changes must follow code-standards including strict error-handling patterns.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/renderer/renderToDrawlist/renderTree.ts` at line 128, The
assignment "const currentTheme = themeStack.pop() ?? theme" can silently hide
themeStack underflow; add a dev-only guard before popping themeStack in the
renderTree logic (referencing themeStack, currentTheme, and theme) that checks
themeStack.length > 0 and if not, throws or logs a clear error (using the
project's dev flag like NODE_ENV or __DEV__) so traversal bugs surface during
development, while in production still falling back to `theme`.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/core/src/renderer/renderToDrawlist/renderTree.ts`:
- Line 128: The assignment "const currentTheme = themeStack.pop() ?? theme" can
silently hide themeStack underflow; add a dev-only guard before popping
themeStack in the renderTree logic (referencing themeStack, currentTheme, and
theme) that checks themeStack.length > 0 and if not, throws or logs a clear
error (using the project's dev flag like NODE_ENV or __DEV__) so traversal bugs
surface during development, while in production still falling back to `theme`.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f3900d4 and 926fd75.

📒 Files selected for processing (1)
  • packages/core/src/renderer/renderToDrawlist/renderTree.ts

@RtlZeroMemory RtlZeroMemory merged commit 090481d into main Feb 26, 2026
41 of 44 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.

1 participant