fix(ios): perf issues w/ image masks#57399
Open
hannojg wants to merge 3 commits into
Open
Conversation
hannojg
commented
Jul 1, 2026
| _props = defaultProps; | ||
|
|
||
| _imageView = [RCTUIImageViewAnimated new]; | ||
| _imageView.clipsToBounds = YES; |
Contributor
Author
There was a problem hiding this comment.
This is not really needed as the outer RCTViewComponentView will properly do the clipping / apply a mask, so this is actually redundant here
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Two years ago, in this PR:
a fix for this issue was introduced:
This fix can cause performance issues as we are applying a mask which is rendering wise a heavy operation, often causing the rendering phase to do multiple offscreen draw passes.
We noticed this to a considerable, measure-able effect in the discord app.
This specific case for
UIImageViews:react-native/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm
Lines 1316 to 1323 in 4aef2b0
is really only needed when:
The reason we need this handling is for content to not draw over the border like this:
However, when the user just wants to add a border radius (e.g.
borderRadius: 10), applying a mask is not needed. The image will be correctly "cut out" by the parentRCTViewComponentViewapplying thecornerRadius, which is much better performance wise.Hence my fix here is to simply disable this special handling when its not needed.
The performance gain
Code for `RNTesterPlayground.js`
I created an example case where we render a list of images that have
borderRadius: 4and scrolled it for a bit and performance profiled it using the xcode instruments:Here are the differences when it comes to render & offscreen passes, as well as CPU and GPU usage:
Changelog:
[IOS] [FIXED] - Performance: don't unnecessarily apply masks to
UIImageViewTest Plan:
In RNTester, where i added two new example cases for image borders, you can verify that the border radii examples are still working as expected: