Skip to content

[performance] Optimize useHover hooks and safePolygon hot paths#4199

Merged
atomiks merged 8 commits intomui:masterfrom
atomiks:codex/hover-safepolygon-perf
Mar 5, 2026
Merged

[performance] Optimize useHover hooks and safePolygon hot paths#4199
atomiks merged 8 commits intomui:masterfrom
atomiks:codex/hover-safepolygon-perf

Conversation

@atomiks
Copy link
Contributor

@atomiks atomiks commented Feb 26, 2026

Purely perf-related change for bundle size + runtime cost

@atomiks atomiks added performance scope: all components Widespread work has an impact on almost all components. labels Feb 26, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 26, 2026

commit: 9ccef50

@mui-bot
Copy link

mui-bot commented Feb 26, 2026

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react ▼-36B(-0.01%) ▼-86B(-0.06%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify
Copy link

netlify bot commented Feb 26, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 87abf70
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69a8f1fb9e08790008771b38
😎 Deploy Preview https://deploy-preview-4199--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks atomiks force-pushed the codex/hover-safepolygon-perf branch from 61789be to 87b8888 Compare February 26, 2026 03:28
@atomiks atomiks marked this pull request as ready for review February 26, 2026 03:54
Copy link
Member

@flaviendelangle flaviendelangle left a comment

Choose a reason for hiding this comment

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

Only one concern from Claude Code
Nice to have perf improvement AND bundle size reduction in the same PR 🔥

@github-actions github-actions bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Mar 2, 2026
@atomiks
Copy link
Contributor Author

atomiks commented Mar 3, 2026

Codex Review

Overview

This PR refactors hover and safePolygon hot paths, extracts shared hover delay helpers, and adds targeted tests around wrapper-trigger handling and safePolygon geometry. I reviewed the full upstream/master...head diff and the latest commit on this branch.

Findings

No blocking issues found in this patch.

1. ℹ️ [Informational] safePolygon hot path is faster than master in the focused micro-benchmark

Impact: The main performance-sensitive path reviewed here shows a measurable win relative to master, so the scalar geometry rewrite does not introduce a runtime regression in this check.

Evidence: packages/react/src/floating-ui-react/safePolygon.ts plus the new safePolygon tests (packages/react/src/floating-ui-react/safePolygon.test.ts) were benchmarked with the same harness on both refs (120 samples, 2500 events/sample, safePolygon({ requireIntent: false }) hot path).

Ref Mean (us/event) p50 (us/event) p95 (us/event) Samples
upstream/master (0824de08c) 0.1393 0.1136 0.2006 120
PR head (87abf70dd) 0.0755 0.0540 0.1600 120

Recommendation: No change required for this path based on current evidence.

2. ℹ️ [Informational] DRY simplification in hover delay utilities is clean

Impact: Delay resolution and pointer-type gating are now centralized, which lowers maintenance surface without changing public behavior.

Evidence: packages/react/src/floating-ui-react/hooks/useHoverShared.ts centralizes resolution in resolveValue, and packages/react/src/floating-ui-react/hooks/useHoverFloatingInteraction.ts now reuses getDelay(..., 'close', ...) instead of a separate close-only helper.

Recommendation: Keep this structure as-is.

Confidence: 4/5

High confidence from a full-branch diff review, targeted behavioral tests in touched modules, and a direct head-vs-master micro-benchmark on the main hot path.

Notes

  • Review scope covered all files changed in this branch, not just the latest commit.
  • CI bundle delta should be read from the latest bot run on current head (87abf70dd).

@atomiks atomiks force-pushed the codex/hover-safepolygon-perf branch from 97dd2b9 to c9874e3 Compare March 4, 2026 06:20
@atomiks atomiks force-pushed the codex/hover-safepolygon-perf branch from 5417a32 to 5ee47db Compare March 5, 2026 02:56
@atomiks atomiks merged commit 1cd3d87 into mui:master Mar 5, 2026
21 of 22 checks passed
@atomiks atomiks deleted the codex/hover-safepolygon-perf branch March 5, 2026 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance scope: all components Widespread work has an impact on almost all components.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants