Skip to content

perf(settings): memoize derived policy templates to trim render work#1199

Merged
kryputh merged 6 commits into
Stellar-Mail:mainfrom
AbuJulaybeeb:issue-938-policy-editor-perf
Jun 29, 2026
Merged

perf(settings): memoize derived policy templates to trim render work#1199
kryputh merged 6 commits into
Stellar-Mail:mainfrom
AbuJulaybeeb:issue-938-policy-editor-perf

Conversation

@AbuJulaybeeb

Copy link
Copy Markdown
Contributor

What was done

  • Wrapped heavily derived policy calculations (currentDraft, liveTemplate, selectedPreview, selectedPreferences, previewMatchesCurrent, and applyingWillReplaceCurrent) inside useMemo hooks inside the InboxSettings component.
  • Stabilized the references for the currentDraft object, ensuring referential equality is preserved across re-renders when nothing changes.
  • Wrapped all user-interaction functions (handleTemplateChange, handleApply, handleSaveCustom, updateUnknownSenders, and updateMinimumPostage) with useCallback to prevent inline function recreation.

Why it was done

Prior to this change, the InboxSettings recalculations and object instantiations were triggered on every render cycle. Because the minimumPostage is controlled by a continuous input field, every single keystroke was forcing React to re-compute the comparison logic against the built-in MAILBOX_POLICY_TEMPLATES array and re-instantiate local closures. Memoizing these expensive dependency chains significantly reduces unnecessary reconciliation latency and provides a snappier feeling while tweaking postage values.

How it was verified

  • Verified no broad refactors were performed; optimizations were scoped strictly to src/components/mail/SettingsModal.tsx.
  • Ensured there is no visible regression in behavior—the custom draft tracking and explicit overwrite logic still works seamlessly.
  • Ran tsc --noEmit locally (the only errors are pre-existing type errors outside the modified scope) to ensure proper React hook dependencies were included.

closes #938

@AbuJulaybeeb AbuJulaybeeb force-pushed the issue-938-policy-editor-perf branch from 4d6dd34 to c1e18fe Compare June 22, 2026 03:14
@kryputh kryputh merged commit 6238e74 into Stellar-Mail:main Jun 29, 2026
5 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.

[Existing app][Policy Editor] Trim render work and loading latency

2 participants