Skip to content

fix(react-avatar): make enclosure cleanup linear - #36738

Open
Tudor Popa (tudorpopams) wants to merge 1 commit into
microsoft:masterfrom
tudorpopams:orchestrator/fluentui/reproducer-55370cb7b33f
Open

Tudor Popa (tudorpopams) wants to merge 1 commit into
microsoft:masterfrom
tudorpopams:orchestrator/fluentui/reproducer-55370cb7b33f

Conversation

@tudorpopams

Copy link
Copy Markdown
Contributor

Previous Behavior

Avatar's default name-to-initials path repeatedly rescanned unterminated enclosure text. Runs of opening parentheses, square brackets or braces incurred quadratic processing time even though the resulting initials were unchanged.

New Behavior

Replace enclosure matching with one indexed UTF-16 scan. Preserve the existing rule: the first opening delimiter is removed through the next closing delimiter, regardless of delimiter type or nesting. Retain unterminated text and leave Unicode/surrogate handling, RTL, firstInitialOnly, unsupported-language filtering, whitespace cleanup and phone-number behavior unchanged.

The implementation lazily collects nonempty retained spans and joins them once. It introduces no per-character buffer, nesting stack, input truncation, dependency or public API. A patch change entry is included for @fluentui/react-avatar.

Local Results

The original bounded regression was replayed unchanged, including its threshold and watchdogs. For 1,024 to 4,096 unmatched square brackets, median processing time changed from approximately 0.611 to 9.663 ms before the repair to 0.00579 to 0.0210 ms after the repair. These are local bounded measurements, not a general timing guarantee. The parentheses and braces assertions also passed.

All 163 Avatar tests passed, including the public Avatar name path, all nine opening/closing delimiter combinations, Unicode cases and a deterministic comparison of all 7,381 strings of length zero through four over a nine-character alphabet against the previous enclosure semantics. Avatar lint, build and type-check passed. Missing local compiled entry points were resolved with the existing eslint-plugin-react-components and react-avatar build targets, without reinstalling dependencies or changing configuration.

Independent pre-commit review approved the exact diff, now committed as 3c93665. The identical original regression and all 163 Avatar tests passed again on that clean committed head. The timings and lint/build/type-check results above are the earlier pre-commit observations. Independent committed-head review and assessment passed for this exact head; no CI readiness is claimed here.

Related Work

PHONENUMBER_REGEX is unchanged, keeping the enclosure optimization separate from #36711.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved issues were identified that would block approval.

Pull request overview

Replaces quadratic enclosure cleanup in Avatar initials generation with a linear UTF-16 scan while preserving existing behavior.

Changes:

  • Added indexed enclosure removal.
  • Added semantic and performance regression tests.
  • Added a patch release change file.
File summaries
File Description
packages/react-components/react-avatar/library/src/utils/getInitials.ts Updated as part of this pull request.
packages/react-components/react-avatar/library/src/utils/getInitials.test.ts Updated as part of this pull request.
packages/react-components/react-avatar/library/src/utils/getInitials.enclosures.test.tsx Updated as part of this pull request.
change/@fluentui-react-avatar-43a7ed01-2573-4a4a-9a5b-6b56387b4e86.json Updated as part of this pull request.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-avatar
Avatar
48.256 kB
15.276 kB
48.462 kB
15.362 kB
206 B
86 B
react-avatar
AvatarGroupItem
61.24 kB
19.139 kB
61.446 kB
19.221 kB
206 B
82 B
react-components
react-components: all base hooks
217.893 kB
68.338 kB
218.099 kB
68.438 kB
206 B
100 B
react-components
react-components: entire library
1.283 MB
322.086 kB
1.283 MB
322.171 kB
206 B
85 B
react-headless-components-preview
react-headless-components-preview: entire library
242.029 kB
68.213 kB
242.235 kB
68.29 kB
206 B
77 B
react-persona
Persona
55.209 kB
17.22 kB
55.415 kB
17.303 kB
206 B
83 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-avatar
AvatarGroup
17.269 kB
6.89 kB
react-components
react-components: Button, FluentProvider & webLightTheme
67.471 kB
19.465 kB
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
227.136 kB
68.41 kB
react-components
react-components: FluentProvider & webLightTheme
40.694 kB
13.549 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/tag-picker
54.012 kB
17.756 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/teaching-popover
36.073 kB
12.006 kB
react-portal-compat
PortalCompatProvider
5.341 kB
2.146 kB
react-table
DataGrid
147.809 kB
43.977 kB
react-table
Table (Primitives only)
38.042 kB
12.69 kB
react-table
Table as DataGrid
119.68 kB
33.755 kB
react-table
Table (Selection only)
66.557 kB
18.957 kB
react-table
Table (Sort only)
65.22 kB
18.58 kB
react-tag-picker
@fluentui/react-tag-picker - package
174.763 kB
54.56 kB
react-tags
InteractionTag
13.629 kB
5.386 kB
react-tags
Tag
29.542 kB
9.338 kB
react-tags
TagGroup
70.806 kB
21.811 kB
react-timepicker-compat
TimePicker
142.037 kB
46.44 kB
react-tree
FlatTree
136.693 kB
40.821 kB
react-tree
PersonaFlatTree
138.556 kB
41.361 kB
react-tree
PersonaTree
134.637 kB
40.143 kB
react-tree
Tree
132.78 kB
39.638 kB
🤖 This report was generated against e8033487274728d29528055e3aadf6c75e65e4cc

@github-actions

Copy link
Copy Markdown

Pull request demo site: URL

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.

3 participants