Skip to content

feat: optimize 'when' directive for fixed templates - #7783

Merged
John Kreitlow (radium-v) merged 1 commit into
mainfrom
users/radium-v/make-when-faster
Oct 28, 2026
Merged

John Kreitlow (radium-v) merged 1 commit into
mainfrom
users/radium-v/make-when-faster

Conversation

@radium-v

Copy link
Copy Markdown
Collaborator

Pull Request

📖 Description

Reduce when overhead when both branches are fixed templates. The new path avoids creating and calling wrapper functions, and selects the result once when the condition is constant.

Template bindings still run only for the selected branch. A false condition without an else template still returns null. Includes regression tests and updated API docs and size reports.

👩‍💻 Reviewer Notes

Chromium microbenchmarks showed 25–29% lower construction time and 3–9% lower evaluation time for dynamic conditions with fixed templates. These measurements exclude DOM rendering.

The focused when export grows from 731 to 781 bytes gzipped.

📑 Test Plan

  • All 13 tests in the focused when suite passed.
  • Coverage includes constant and expression conditions, missing else templates, and fixed and bound template combinations.
  • New tests check lazy evaluation, source and context forwarding, and subscription changes when the active branch changes.

✅ Checklist

General

  • I have included a change request file using $ npm run change
  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I have read the CONTRIBUTING documentation and followed the standards for this project.

Agents

  • I have linked to an existing issue in this project that this change addresses
  • I have read the skills
  • I have read the DESIGN.md file(s) in packages relevant to my changes
  • I have updated the DESIGN.md file(s) in packages relevant to my changes

@radium-v
John Kreitlow (radium-v) merged commit 2e3880f into main Oct 28, 2026
11 checks passed
@radium-v
John Kreitlow (radium-v) deleted the users/radium-v/make-when-faster branch October 28, 2026 23:46
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