Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftUI View Extension: Improve pointer interaction #1961

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

imthath-m
Copy link
Contributor

@imthath-m imthath-m commented Jan 30, 2024

Avoiding AnyView because it erases the identity of the View and can cause performance issues

Platforms Impacted

  • iOS
  • macOS

Description of changes

Avoiding AnyView because it erases the identity of the View and causes performance issues. Using new hoverEffect(_:) modifier which accepts a boolean in iOS 17+.

Binary change

Total increase: 3,74,192 bytes
Total decrease: 0 bytes

File Before After Delta
Total 3,11,49,392 bytes 3,15,23,584 bytes ⛔️ 3,74,192 bytes

I don't fully understand how such a small changes causes 350kb difference.

Full breakdown
File Before After Delta
IndeterminateProgressBar.o 2,33,984 bytes 3,65,752 bytes 🛑 1,31,768 bytes
__.SYMDEF 48,86,280 bytes 50,12,696 bytes 🛑 1,26,416 bytes
Avatar.o 6,02,160 bytes 7,18,152 bytes 🛑 1,15,992 bytes
SwiftUI+ViewModifiers.o 1,36,096 bytes 1,36,112 bytes ⚠️ 16 bytes

Verification

avatar-ipad-pointer.mp4

Tested on the Avatar SwiftUI demo, the iPad pointer interaction works as before.

No Visual Change.

Pull request checklist

This PR has considered:

  • Light and Dark appearances
  • iOS supported versions (all major versions greater than or equal current target deployment version)
  • VoiceOver and Keyboard Accessibility
  • Internationalization and Right to Left layouts
  • Different resolutions (1x, 2x, 3x)
  • Size classes and window sizes (iPhone vs iPad, notched devices, multitasking, different window sizes, etc)
  • iPad Pointer interaction
  • SwiftUI consumption (validation or new demo scenarios needed)
  • Objective-C exposure (provide it only if needed)
Microsoft Reviewers: Open in CodeFlow

@imthath-m imthath-m requested a review from a team as a code owner January 30, 2024 12:09
Copy link
Contributor

@mischreiber mischreiber left a comment

Choose a reason for hiding this comment

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

I don't fully understand how such a small changes causes 350kb difference.

This is because you are extending a protocol in a way that specifies some View as a return type. As such, the Swift compiler needs to generate a copy of this function each time it's used on any view to convert that to the concrete type of the view. The current implement wraps its return in AnyView and thus is generic enough to not require this.

You mentioned in your PR that AnyView causes performance issues. Can you elaborate?

@imthath-m
Copy link
Contributor Author

You can find info about performance issues because of AnyView in this article. This article references related developer docs and WWDC videos as well.

The only place where it is currently exposed from FluentUI is when we use Avatar(_:_:).hasPointerInteraction(true). The more SwiftUI components FluentUI supports, this will be exposed from different places and could cause more issues. I noticed it while working on the SwiftUI button here #1960.

Avoiding AnyView because it erases the identity of the View and can cause performance issues
@mischreiber
Copy link
Contributor

Out of curiosity, can you also run the process under Step 9 of the Size Comparison wiki and post your results too? Size Comparison · microsoft/fluentui-apple Wiki (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.

None yet

2 participants