Skip to content

Conversation

@mattcosta7
Copy link
Contributor

@mattcosta7 mattcosta7 commented Dec 15, 2025

Summary

Performance optimizations for AvatarStack component to improve INP (Interaction to Next Paint).

Changes

  1. CSS :has() selector optimization - Scope :has([data-square]) to direct child with > combinator
  2. MutationObserver throttling - Batch callbacks using requestAnimationFrame

Expected INP Impact

Scenario Before After Improvement
Worst case (rapid DOM mutations, many avatars) ~30-50ms per mutation batch <16ms (1 frame) 50-70% reduction
Average case (occasional updates, 3-5 avatars) ~10-20ms style recalc <5ms 50-75% reduction
Best case (static content) ~5ms style recalc <2ms ~60% reduction

Why this matters

  • :has() optimization: Unscoped :has() forces full subtree traversal. Direct child selector is O(1).
  • MutationObserver throttling: Without throttling, rapid mutations can trigger multiple state updates per frame, causing jank. rAF batching ensures max 1 update per frame.

Part of the INP performance optimization effort. See #7312 for full context.

…Observer

- Scope :has([data-square]) to direct child with > combinator for O(1) lookup
- Throttle MutationObserver callback using requestAnimationFrame to batch DOM reads

Part of #7312
@changeset-bot
Copy link

changeset-bot bot commented Dec 15, 2025

🦋 Changeset detected

Latest commit: 888c37f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Dec 15, 2025
@github-actions
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Or, apply the integration-tests: skipped manually label to skip these checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants