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

Speed up Home initialization #2259

Merged
merged 6 commits into from
Jan 15, 2025
Merged

Speed up Home initialization #2259

merged 6 commits into from
Jan 15, 2025

Conversation

paultranvan
Copy link
Contributor

This is meant to speed up to Home initialization and thus its display, particularly for the flagship app.

Measured time:
[Web]

  • Before : ~576ms
  • After: ~130ms

[React-Native]

  • Before : ~719ms
  • After: ~178ms

For both environments, this is roughly a 4x in performances.

### ✨ Features

* Improve starting time

### 🐛 Bug Fixes

*

### 🔧 Tech

*

zatteo and others added 5 commits January 14, 2025 16:50
Old file now unused moved in cozy-dataproxy-lib.
The apps are already fetched at the root component
and checked to determine if the app is initialized.
There is no need to have additional custom logic
pass down to children component.
When querying the triggers on the `worker` field, it uses a stack route that will
complete the trigger information with jobs.
This is costful, as it makes additional database requests, and useless at startup
time.
So, we now uses a `partialIndex` that will uses the `/find` route and make a
faster query.

See https://github.com/cozy/cozy-client/blob/c6762bb0c1fad4ac62f18b4118c8577a749caf2b/packages/cozy-stack-client/src/TriggerCollection.js#L125
and
https://github.com/cozy/cozy-stack/blob/master/docs/jobs.md#post-jobstriggers
We get rid of the  complicated state management to determine whether or not the
Home is initialized, to rely on a dedicated hook in charge of fetching all the required
data.
Note the Home is relying on this mechanism to later fetch data directly from the store.
In the future, we might have the same logic, but relying on the dataproxy directly
Copy link

bundlemon bot commented Jan 14, 2025

BundleMon

Files updated (7)
Status Path Size Limits
intents/home.(hash).js
25.82KB (+125B +0.48%) -
services/deleteAccounts/home.js
311.95KB (+67B +0.02%) -
services/myselfFromIdenties/home.js
236.35KB (+66B +0.03%) -
services/softDeleteOrRestoreAccounts/home.js
466.15KB (+64B +0.01%) -
services/updateAccounts/home.js
463.29KB (+63B +0.01%) -
app/home.(hash).js
48.73KB (+42B +0.08%) -
vendors/home.(hash).js
1.8MB (-800B -0.04%) -
Unchanged files (6)
Status Path Size Limits
services/polyfillFetch/home.js
97.38KB -
vendors-home.(hash).(hash).min.css
38.02KB -
services/attributesHelpers/home.js
15.22KB -
app-home.(hash).min.css
1.96KB -
intents/index.html
648B -
intents-home.(hash).min.css
158B -

Total files change -374B -0.01%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@@ -18,7 +18,7 @@ export const makeTriggersQuery = {
definition: () => {
return Q('io.cozy.triggers')
.partialIndex({
worker: 'konnector'
worker: { $in: ['client', 'konnector'] } // client is for CLISK
Copy link
Contributor

Choose a reason for hiding this comment

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

Sadly, as you explain in the description of this commit, this request does not fetch jobs. And these jobs are needed to compute the current_state attribute of the trigger which is needed to know if the trigger has any error.

I must admit I have some difficulties to follow the flow of the front code to know where and how it is used but if I try your branch in my local cozy, I don't have any error status displayed on konnector icons in home application.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sigh looks like I missed this case. I guess we could query the triggers with job info at the moment we click on the konnector "group" as it is at his moment that we display the error icon, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See 48e75e1

log('info', `Required data fetched in ${endTime - startTime.current} ms`)
loggedTime.current = true
}
}, [allQueries])
Copy link
Contributor

Choose a reason for hiding this comment

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

You want to keep this monitoring in production ?

Copy link
Contributor Author

@paultranvan paultranvan Jan 15, 2025

Choose a reason for hiding this comment

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

Yes, because it might be later useful, and I don't see a strong problem with it, as the impact will be negligible. But I'm open to contradiction if you think this is bad practice

Copy link
Contributor

Choose a reason for hiding this comment

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

It was just to be sure it was not a miss.

Also, I'm sure there are ways to monitor these kind of things with Sentry. But there's a time for everything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes a sailor told me that before he left :)
Let's keep it like this for now, it seems reasonable and might evolve in the future

@zatteo
Copy link
Contributor

zatteo commented Jan 15, 2025

Well done !

@doubleface doubleface self-requested a review January 15, 2025 13:17
We used to query triggers with their `current_state` at Home startup. We
removed it for performances purposes, but now it is only made when the
focus event is fired. This means we can miss this state when entering a
konnector group, which is required to correctly display the icons.
So, we query the triggers when required, and mutualize it with the focus
queries to benefit from the redux store.
@paultranvan paultranvan merged commit 13c8a64 into master Jan 15, 2025
4 checks passed
@paultranvan paultranvan deleted the improve-start-perfs branch January 15, 2025 14:07
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.

3 participants