-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[Performance] [Audit] ThumbnailImage
triggers layout shifts, impeding FlatList performance
#4115
Comments
Triggered auto assignment to @stephanieelliott ( |
ThumbnailImage
triggers layout shifts, impeding FlatList performance
Oh wow, yeah this sounds like it could be pretty bad depending on how costly it is to recompute the position. I feel like we should be able to test the impacts with a very simple test case where 2 chats are switched back and forth and timed. e.g. one will have 500 regular comments the other has 499 comments and 1 attachments (or more) then we compare the difference.
Open to hearing thoughts on how we can store this information. It would be nice if there is some way to do this at the server level when generating the HTML for the image. Otherwise I think we will need to cache the size or delay rendering the |
I'm pretty sure this would affect the position of every cell in the virtualized portion that is loaded, but I'm not certain it will recompute/re-render cells besides the ones containing images that change The reason is we don't implement |
Just want to point out that this scaling behavior is already implemented in react-native-render-html internal Image component. You can reuse the internal component in the custom renderer such as described here; just replace See also default implementation: |
Oh nice! In that case we should just be able to store the height/width with the image when we generate it and remove a lot of the |
Triggered auto assignment to @robertjchen ( |
Triggered auto assignment to @NicMendonca ( |
Still no internal takers on https://github.com/Expensify/Expensify/issues/173677. I may pick it up before week's end if nobody beats me to it. |
Holding for N6 |
Still no takers on the internal GH. |
No progress to speak of. |
No takers yet. Bumping this down to Monthly. |
Still no internal takers on https://github.com/Expensify/Expensify/issues/173677 |
That internal GH has has been closed by Melvin. There have been some other discussions in the contributor sphere around ways to speed up image performance that may address the findings from this audit, so maybe by the next time it gets marked overdue we can just close it. |
I see we now have When you switch to different device you'll probably experience the problem again, or when you're cache expires Adding the width and height to the |
Agreed, @kidroca. Going to close this since we've taken differing approaches to speeding up image handling. |
If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!
This report is part of #3957, scenario "Rendering Individual chat messages".
Flamegraph
The full commit log can be inspected with Flipper or React Devtools, see #3957 (comment) for instructions.
You can witness the layout shift behavior in the below Framegraph (c244, select
VirtualizedList
component)The four commits (c222, c244, c266 and c280) are caused by
last
state ofVirtualizedList
component being changed, this is the signature of layout shifts. There are exactly 3 images in the report. So we have 1 initial commit + 3 layout shifts. Those 3 layout shifts span over 1.3s, this is considerable.To get more into the details of
VirtualizedList
internals, a layout shift causes_onCellLayout
callback to be invoked,which calls
_scheduleCellsToRenderUpdate
which calls_updateCellsToRender
, which in turn causeslast
state to change.Cause
https://github.com/Expensify/Expensify.cash/blob/76c3157a41d86beb89c8cf107a68573280c06ce7/src/components/ThumbnailImage.js#L59-L63
The
ThumbnailImage
component first draws a 100x100 box to display the image, then waits for physical dimensions to be available and redraws the image with the newfound dimensions. This causes theFlatList
cell layout to shift, and requiresFlatList
to recompute the position of each cell. This can have a sensible impact on performance if a discussion has many image attachments, since every shift will cause theFlatList
to recompute the position of each cell, potentially re-rendering some cells.Proposal: store images physical dimensions in markup
Store the physical dimensions of the image as attributes (
width
,height
) of the<img>
element. Thus, we can render the image one and only once and avoid those costly shifts.The text was updated successfully, but these errors were encountered: