Skip to content

Perf: Memoize regex parsing in convertConditionToConditions - #1

Draft
collinversluis wants to merge 1 commit into
mainfrom
claude/perf-pr1-condition-regex-memoize
Draft

Perf: Memoize regex parsing in convertConditionToConditions#1
collinversluis wants to merge 1 commit into
mainfrom
claude/perf-pr1-condition-regex-memoize

Conversation

@collinversluis

Copy link
Copy Markdown
Member

Summary

convertConditionToConditions is called once per condition evaluation per element during editor boot. Each call re-parses the same condition strings into regex matches. Cache the parse result by raw input string.

  • Pure caching — same input string → same parsed result
  • No behavior change, no experiment flag required
  • 1 file, ~37 LoC

Impact

Profile-attributable savings depend on element count and condition density. On a 200-widget bench this lands a small but unconditional win (no flag to flip).

Test plan

  • Editor loads with no regressions on a standard widget mix
  • Condition-driven control visibility (e.g. text-align showing/hiding based on alignment) still works
  • Cache does not retain stale results across distinct condition strings

Notes

Standalone cherry-pick from claude/great-mayer-klkFh (perf-build fork). No dependency on any experiment. First of four planned surgical PRs from the perf branch.


Generated by Claude Code

Phase 6 of the perf series.

The first half of convertConditionToConditions runs two regex .match() calls on
conditionName, returning four derived strings. The result depends only on the
string conditionName — not on the conditionValue, controlModel, values, or
controls arguments — yet the same names recur many times across element and
widget instances on a page ('selected_icon[value]!' once per heading-with-icon,
etc.). The user's CPU profile flagged convertConditionToConditions at 704ms
self-time on a 200-element page.

This adds a module-scoped Map cache keyed on conditionName with a 2000-entry
safety cap. No behavior change; cache miss runs the original regex work.

Not gated by an experiment flag — pure memoization with identical output, no
observable semantic change. Easy to revert via git revert if needed.
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