Skip to content

Perf: Optimize font name matching with Set - #3374

Draft
TomA-R wants to merge 1 commit into
masterfrom
fix/hosted-field-font-optimization
Draft

Perf: Optimize font name matching with Set#3374
TomA-R wants to merge 1 commit into
masterfrom
fix/hosted-field-font-optimization

Conversation

@TomA-R

@TomA-R TomA-R commented Aug 24, 2026

Copy link
Copy Markdown
Member

Summary

Improves performance of font URL matching in hosted form.

Issue

The _getFontUrls() method was iterating through all style values for each link element,
resulting in O(nmk) complexity.

Changes

  • Pre-cache all font names into a Set before filtering links
  • Check each link against the cached Set

Performance Impact

  • Reduces nested loop complexity significantly
  • Only called during form initialization, but improves overall responsiveness
  • Better scalability with more styles or links

Testing

  • Build passes with NX
  • No breaking changes to API

Note

Low Risk
Small, local performance refactor of font URL filtering with no API or security changes.

Overview
Speeds up Google Fonts URL matching in hosted fields by collecting fontFamily names into a Set once, then filtering stylesheet links against that cache instead of re-walking styles for every link.

Behavior of _getFontUrls() is unchanged: it still returns fonts.googleapis.com stylesheet hrefs whose URLs contain a configured font name.

Reviewed by Cursor Bugbot for commit 45b0315. Bugbot is set up for automated code reviews on this repo. Configure here.

Pre-cache font names from styles into a Set for O(1) lookup instead of
repeatedly iterating through all styles for each link element.

This reduces the nested loop complexity from O(n*m*k) to O(n*k + m) where:
- n = number of link elements
- m = number of style objects
- k = average font names per family string

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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