-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[Performance] Update withWindowDimensions
HOC to use a Context Provider internally
#2326
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
Comments
ProposalI've included everything in the ticket description. I think, with the explanation above, this is something anyone should be able to do. But since I brought it up I would like to work on this or at least take some credit 😉 |
Great summary here and thanks for putting this together! I think we are just missing something about what the practical impacts of such a change would be. Is there a way to apply this solution to a measurable outcome or some specific problem? e.g. I see mention that this should be addressed due to memory usage issues. But I'm not sure I'm aware of any issues directly related to memory usage. So,
If this issue was accompanied by something like "we are consuming x memory and this change will reduce memory consumption by y amount which will make the app run z seconds faster" then I think we could start right away. |
At the time I didn't know a lot about your workflow and that I should present hard evidence of a problem Looking at the implementation and usages throughout the code I just know it isn't optimal and provide explanation on that. To provide hard evidence and metrics for an issue like that could cost a lot of extra time and efforts. And with no guarantee that I'll get a job only makes it harder to justify the labor. I try to provide a good explanation and then you can decide is it worth investigating further. |
I've played around trying to gather enough information to prove this. I did manage to find Performance issue when
|
I understand completely - I can keep looking into this and assign the issue to you if we decide to move forward on it. From our end, it's also hard to justify solving problems when we can't easily evaluate if they are worth fixing. Thanks for the profiles as well. Since they are measuring the impact of a screen adjustment they seem to prove that resizing a window would happen faster if we adopted the suggestion. But not yet sure if this is a case that we should optimize yet. |
Yes but not exactly. It's not that resizing happens slow but reacting to resizes would cost a lot of computing which would affect other stuff happening during that time. Since this is something that would not happen often I can see it not being a priority, but have in mind the mobile web case where when you focus the compose field the keyboard will open and the chat would start re-adjusting while all the This reviews there's a significant relation between the number of instances and performance, it was easier to measure the effects or resizing. |
To clarify, opening the software keyboard will trigger a |
Sorry I thought it did on iOS too. It turns out it's only on Android. Maybe there's nothing that much to gain after all. I cannot trace anything significant back to |
Another case where This issue already deals with this by adding debounce #2180 Even with debounce added there's still a lot of JS scripting time as each HOC would capture its own debounced handler as explained here: #2326 (comment) - "a single change is around 300ms on my desktop workstation" - this is still true, because a single change would still trigger all the debounced handlers (100+) instead of just 1 handler Now that I have a chat with 300+ messages I can try to capture more data regarding other negative effects - e.g. time to load / memory, but I'll wait for chat load time related tickets to close first |
I agree this point make some sense to me denouncing will add extra layer of timeouts. Normally current implementation should not hurt the app even if it adds extra computation. But mostly what I was concerned is the animations, When it comes to animations running on single thread, all these async tasks are a problem. |
Closing this for now. @kidroca Feel free to reopen if you decide to follow up based on this and add the
|
withWindowDimensions
HOC to use a Context Provider internallywithWindowDimensions
HOC to use a Context Provider internally
@parasharrajat please feel free to reopen this issue if you have additional metrics to share. Seems like the last time this was discussed we decided it would not be worth it. But maybe you can find something more concrete. |
Uh oh!
There was an error while loading. Please reload this page.
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
withWindowDimensions
can be improved through a refactor that won't change existing usages and behaviorCurrently State:
withWindowDimensions
HOCs mountedwithWindowDimensions
HOCs mountedAll of these usages would create a separate class component that:
this.onDimensionChange = this.onDimensionChange.bind(this);
withWindowDimensions
instancesThe main problem with this HOC is not that
onDimensionChange
is called often - it's not called at all during init. But initializing a chat with many messages could be choking. On mWeb showing/hiding the keyboard would trigger all theonDimensionsChange
listeners, because the viewport do change. This might be something that is causing extra effort combined with the autofocus making the keyboard appearThis functionality can be split in two:
DimensionsContextProvider
A component that will wrap the App the way the
SafeAreaProvider
does hereIt will have the
class
logic currently defined inwithWindowDimensions
. The difference is it will only mount and subscribe to Dimension events once and will provide any changes to context consumers. When dimensions change the context state will change and all consumers will update the way they currently do. the memory involved doesn't change as usages grow e.g. O(1) vs O(n)withWindowDimensions as a DimensionContextConsumer
The HOC will become just a stateless function that passes contextual value to the wrapped component e.g.:
Add some throttle or debounce
Wrapping the event handler with throttle or debounce from underscore, should further improve resize performance
This is a branch setup with some logging that you can use to play around: kidroca@e2126bc
Originally posted here: #2051 (comment)
Expected Result:
Using the
withWindowDimensions
should not increase memory usage or subscribe unnecessary listenersActual Result:
Each
withWindowDimensions
usage creates a new component with own lifecycle and own subscription to Dimension eventsAction Performed:
N/A
Workaround:
No workaround needed. This is a code organization and performance improvement
Platform:
Where is this issue occurring?
Version Number: 1.0.17-3
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation\
withWindowDimensionsSample.mp4
Expensify/Expensify Issue URL: N/A
The text was updated successfully, but these errors were encountered: