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

feat: Add PerformanceApi to CozyClient #1574

Merged
merged 6 commits into from
Dec 20, 2024
Merged

feat: Add PerformanceApi to CozyClient #1574

merged 6 commits into from
Dec 20, 2024

Conversation

Ldoppea
Copy link
Member

@Ldoppea Ldoppea commented Dec 17, 2024

We want to be able to measure CozyClient's performances in web apps but also in mobile apps

To make this possible we introduce the PerformancesAPI (full documentation available in the PR)

This API should be injected in CozyClient's constructor, then CozyClient will be able to use it to measure performances

This API is meant to wrap platforms' native APIs. On web browsers we wrap the well known Performance API, but on mobile app we may want to use the implementation from react-native-performances

The CozyClient provides the web implementation, but other implementation should be implemented by consuming apps and then injected in the CozyClient's constructor

If no implementation is injected in the constructor, then the defaultPerformance implementation is used. This implementation does nothing, so there is no impact on web apps by default

Here is the result when using the browser's Performance devtools :
performances_devtools

Related link:
https://developer.mozilla.org/en-US/docs/Web/API/Performance


TODO:

  •  Add documentation for the new API
  • Add link to the Flagship implementation to the Other platforms section of the documentation

@Ldoppea Ldoppea force-pushed the feat/performances branch 5 times, most recently from b3815e2 to c41c4a6 Compare December 19, 2024 10:22
@Ldoppea Ldoppea marked this pull request as ready for review December 19, 2024 10:23
We want to be able to measure CozyClient's performances in web apps but
also in mobile apps

To make this possible we introduce the PerformanceAPI

This API should be injected in CozyClient's constructor, then
CozyClient will be able to use it to measure performances

This API is meant to wrap platforms' native APIs. On web browsers we
wrap the well known Performance API, but on mobile app we may want to
use the implementation from react-native-performances

The CozyClient provides the web implementation, but other
implementation should be implemented by consuming apps and then
injected in the CozyClient's constructor

If no implementation is injected in the constructor, then the
`defaultPerformance` implementation is used. This implementation does
nothing, so there is no impact on web apps by default

Related link:
https://developer.mozilla.org/en-US/docs/Web/API/Performance
@Ldoppea Ldoppea force-pushed the feat/performances branch 2 times, most recently from 95729c0 to 13bb965 Compare December 19, 2024 10:48
@paultranvan
Copy link
Contributor

paultranvan commented Dec 19, 2024

Some remarks, but excellent work overall with great documentation 👏

packages/cozy-client/src/store/index.js Show resolved Hide resolved
markName: markName,
measureName: `${markName} query or mutate`,
category: 'CozyClientStore'
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Here are for actions that are not query nor mutate, so I think the measureName is wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed here

I renamed it ${markName} no query nor mutate action

markName: markName,
measureName: `${markName} default`,
category: 'CozyClientStore'
})
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the correct measureName should be ${markName} queries here

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed here

I renamed it ${markName} queries but I'm wondering if this is correct too? Those can be queries or mutation? Does "queries" implies this can be also mutation?

const response = action.response
// Data can be null when we get a 404 not found
// see Collection.get()
// but we still need to update the fetchStatus.
if (!response.data) {
performanceApi.measure({
markName: markName,
measureName: `${markName} with data`,
Copy link
Contributor

Choose a reason for hiding this comment

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

${markName} with no data

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed here

Copy link
Member Author

Choose a reason for hiding this comment

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

I also renamed the next one (line 209) with object as there was also a ! operator I missed

markName: markName,
measureName: `${markName} default`,
category: 'CozyClientStore'
})
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure it is really needed to have different measures here, i.e. if there is no data, if there is an array or not, etc.
I think only one measure is enough

Copy link
Member Author

Choose a reason for hiding this comment

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

On my initial tests, this was to have an idea of the frequency of each return path. Not sure if this is still relevant.


On initial implementation, we chose to measure some parts of the code that we estimated useful and with potential high impact on performances (i.e. queries, store management, pouch management etc.)

We excpect to need more measurements in the future but we need to care to keep the balance beetween having useful measurements and to not visualy overload the measurement graphs
Copy link
Contributor

Choose a reason for hiding this comment

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

s/excpect/expect

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed here


We excpect to need more measurements in the future but we need to care to keep the balance beetween having useful measurements and to not visualy overload the measurement graphs

The API is meant to be simple to use so measurements can be quickly added temporarily in development environements
Copy link
Contributor

Choose a reason for hiding this comment

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

s/added temporarily/temporarily added

Copy link
Contributor

Choose a reason for hiding this comment

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

s/environements/environments

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed here

The API interface is described in the JSDoc

Example of custom implementations:
- Flagship App: [](TODO ADD LINK)
Copy link
Contributor

Choose a reason for hiding this comment

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

Will we think of this? 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

For sure, the task is on the PR description's todo list, so I should not forget to do it (I won't merge this without adding the link).

Copy link
Member Author

Choose a reason for hiding this comment

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


The consuming app is then responsible to inject an implementation or keep the default one that doesn't do any profiling, regarding if the app is built for development environments or for production

PerformancesAPI seems to have an impact on performances light enough to be kept on production. However, we suggest to disable them in that environement if possible
Copy link
Contributor

Choose a reason for hiding this comment

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

s/environement/environment

Copy link
Contributor

Choose a reason for hiding this comment

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

light enough to be kept on production

Are we sure of this? I guess it's ok for a single measure, but I would assume a significative impact overall, since there can be a lot of measures during an app data lifecycle

Copy link
Member Author

Choose a reason for hiding this comment

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

My guess is that, because the API can measure durations as small as a few μs, on high level methods this should not be perceptible. But this may be different on some API for other platforms. Also I did not find any info about it so this is just a guess.

But that's why I suggested to disable it.

@@ -0,0 +1,169 @@
# Performances analysis
Copy link
Contributor

Choose a reason for hiding this comment

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

This doc is really great!
One small remark is that you seem to really dislike ending dots at the end of sentences 😆

Copy link
Member Author

Choose a reason for hiding this comment

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

This is an old habit from one of my first jobs where we avoided adding hard stops at the end of paragraphs on markdown documents.

But I almost have no memories of why this was on guidelines 🙃 (maybe it was something like the rendered that automatically added dot when double \n after a paragraph, but I'm not sure)

I have no opinion on this. I will add them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed here

Copy link
Contributor

@paultranvan paultranvan Dec 19, 2024

Choose a reason for hiding this comment

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

My opinion here is to respect grammar as best as we can 😄
But it's true that we took the habit of missing the final dot in general. Dot.

Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 19, 2024
As we encounter some performances issues in the app startup, we want to
add some metrics to understand where time is consumed

All measurement are made through the `measure.ts` helper that wraps the
`react-native-performance` library and fit the incoming CozyClient
performance API

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 19, 2024
In cozy/cozy-client#1574 we implemented a new CozyClient API that allow
to enable CozyClient's internal performances measurements

This PR configure CozyClient and related links with a react-native
compatible Performance API

This will allow us to analyse performances issues on CozyClient when
used in the Flagship App environment
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
As we encounter some performances issues in the app startup, we want to
add some metrics to understand where time is consumed

All measurement are made through the `measure.ts` helper that wraps the
`react-native-performance` library and fit the incoming CozyClient
performance API

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
In cozy/cozy-client#1574 we implemented a new CozyClient API that allow
to enable CozyClient's internal performances measurements

This PR configure CozyClient and related links with a react-native
compatible Performance API

This will allow us to analyse performances issues on CozyClient when
used in the Flagship App environment
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
As we encounter some performances issues in the app startup, we want to
add some metrics to understand where time is consumed

All measurement are made through the `measure.ts` helper that wraps the
`react-native-performance` library and fit the incoming CozyClient
performance API

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
In cozy/cozy-client#1574 we implemented a new CozyClient API that allow
to enable CozyClient's internal performances measurements

This PR configure CozyClient and related links with a react-native
compatible Performance API

This will allow us to analyse performances issues on CozyClient when
used in the Flagship App environment
@Ldoppea Ldoppea merged commit f45473e into master Dec 20, 2024
3 checks passed
@Ldoppea Ldoppea deleted the feat/performances branch December 20, 2024 17:05
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
As we encounter some performances issues in the app startup, we want to
add some metrics to understand where time is consumed

All measurement are made through the `measure.ts` helper that wraps the
`react-native-performance` library and fit the incoming CozyClient
performance API

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
`cozy-client` and `cozy-pouch-link` has been upgraded to `51.7.0` in
order to retrieve the new Performance API implementation

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
In cozy/cozy-client#1574 we implemented a new CozyClient API that allow
to enable CozyClient's internal performances measurements

This PR configure CozyClient and related links with a react-native
compatible Performance API

This will allow us to analyse performances issues on CozyClient when
used in the Flagship App environment
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
As we encounter some performances issues in the app startup, we want to
add some metrics to understand where time is consumed

All measurement are made through the `measure.ts` helper that wraps the
`react-native-performance` library and fit the incoming CozyClient
performance API

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
`cozy-client` and `cozy-pouch-link` has been upgraded to `51.7.0` in
order to retrieve the new Performance API implementation

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
In cozy/cozy-client#1574 we implemented a new CozyClient API that allow
to enable CozyClient's internal performances measurements

This PR configure CozyClient and related links with a react-native
compatible Performance API

This will allow us to analyse performances issues on CozyClient when
used in the Flagship App environment
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
As we encounter some performances issues in the app startup, we want to
add some metrics to understand where time is consumed

All measurement are made through the `measure.ts` helper that wraps the
`react-native-performance` library and fit the incoming CozyClient
performance API

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
`cozy-client` and `cozy-pouch-link` has been upgraded to `51.7.0` in
order to retrieve the new Performance API implementation

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
In cozy/cozy-client#1574 we implemented a new CozyClient API that allow
to enable CozyClient's internal performances measurements

This PR configure CozyClient and related links with a react-native
compatible Performance API

This will allow us to analyse performances issues on CozyClient when
used in the Flagship App environment
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
As we encounter some performances issues in the app startup, we want to
add some metrics to understand where time is consumed

All measurement are made through the `measure.ts` helper that wraps the
`react-native-performance` library and fit the incoming CozyClient
performance API

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
`cozy-client` and `cozy-pouch-link` has been upgraded to `51.7.0` in
order to retrieve the new Performance API implementation

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
In cozy/cozy-client#1574 we implemented a new CozyClient API that allow
to enable CozyClient's internal performances measurements

This PR configure CozyClient and related links with a react-native
compatible Performance API

This will allow us to analyse performances issues on CozyClient when
used in the Flagship App environment
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
As we encounter some performances issues in the app startup, we want to
add some metrics to understand where time is consumed

All measurement are made through the `measure.ts` helper that wraps the
`react-native-performance` library and fit the incoming CozyClient
performance API

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
`cozy-client` and `cozy-pouch-link` has been upgraded to `51.7.0` in
order to retrieve the new Performance API implementation

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
In cozy/cozy-client#1574 we implemented a new CozyClient API that allow
to enable CozyClient's internal performances measurements

This PR configure CozyClient and related links with a react-native
compatible Performance API

This will allow us to analyse performances issues on CozyClient when
used in the Flagship App environment
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Jan 16, 2025
As we encounter some performances issues in the app startup, we want to
add some metrics to understand where time is consumed

All measurement are made through the `measure.ts` helper that wraps the
`react-native-performance` library and fit the incoming CozyClient
performance API

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Jan 16, 2025
`cozy-client` and `cozy-pouch-link` has been upgraded to `51.7.0` in
order to retrieve the new Performance API implementation

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Jan 16, 2025
In cozy/cozy-client#1574 we implemented a new CozyClient API that allow
to enable CozyClient's internal performances measurements

This PR configure CozyClient and related links with a react-native
compatible Performance API

This will allow us to analyse performances issues on CozyClient when
used in the Flagship App environment
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Jan 17, 2025
As we encounter some performances issues in the app startup, we want to
add some metrics to understand where time is consumed

All measurement are made through the `measure.ts` helper that wraps the
`react-native-performance` library and fit the incoming CozyClient
performance API

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Jan 17, 2025
`cozy-client` and `cozy-pouch-link` has been upgraded to `51.7.0` in
order to retrieve the new Performance API implementation

Related PR: cozy/cozy-client#1574
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Jan 17, 2025
In cozy/cozy-client#1574 we implemented a new CozyClient API that allow
to enable CozyClient's internal performances measurements

This PR configure CozyClient and related links with a react-native
compatible Performance API

This will allow us to analyse performances issues on CozyClient when
used in the Flagship App environment
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.

2 participants