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

Default enforceSingleInvocation=true #14

Merged
merged 2 commits into from
Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ If you know a better way to measure startup time (in a module), let me know or b

### Mostly automatic installation

This module supports autolinking so if you use RN 0.60+ then no additional action is required.
This module supports autolinking so **if you use RN 0.60+ then no additional action is required**.

Otherwise, run

`$ react-native link react-native-startup-time`

### Manual linking installation

<details>
<summary>Show manual installation steps</summary>

1. Open `./android/settings.gradle`, add this:

```gradle
Expand All @@ -44,20 +47,20 @@ import com.github.doomsower.RNStartupTimePackage;
// Define package
new RNStartupTimePackage()
```
</details>


## Usage

Render startup time badge somewhere on your first screen:

```jsx
import { StartupTime } from 'react-native-startup-time';
...

<StartupTime
ready={true /* optional, defaults to true */}
style={styles.startupTime /* optional*/}
ready={true /* optional, defaults to true */}
style={styles.startupTime /* optional*/}
/>

```

Or use imperative call:
Expand All @@ -71,26 +74,20 @@ getTimeSinceStartup().then((time) => {
});
```

### Ensuring purity of your analytics data
_The following sections are applicable to Android only_

### Single-Sampling

This makes sure Android doesn't resolve the getTimeSinceStartup promise more than once per app execution. More information in [PR #10](https://github.com/doomsower/react-native-startup-time/pull/10).

_This section is applicable to Android only_
Since v1.4.0 this strategy is enabled by default, if you're migrating from a previous version and you just want things to keep working as they are, follow the steps below.

In case you're going to use this library for collecting the performance analytics, be aware to discard redundant samples which may sometimes pop up.
#### Disabling Single-Sampling:

Depending on which lifecycle hook you've attached your call to `getTimeSinceStartup()` you might receive redundant invocations, e.g. when the app is brought from bg to fg. Because the app isn't really starting up, the measured time can be unrealistic; such unrealistic samples adulterate your data and should be avoided.
Be aware, depending on which lifecycle hook you've attached your call to `getTimeSinceStartup()` you might receive redundant invocations, e.g. when the app is brought from bg to fg. Because the app isn't really starting up, the measured time can be unrealistic; such unrealistic samples adulterate your data.

To enforce single-sampling strategy, create your package using constructor with parameter `true`:
To disable single-sampling strategy, create your package using constructor with parameter `false`:
```java
// Define package
new RNStartupTimePackage(true)
new RNStartupTimePackage(false)
```
then sample the startup time with catching the redundant invocation error:
```jsx
// when you app is ready:
getTimeSinceStartup().then((time) => {
// Initial sample. Collect it for your analytics.
})
.catch((e) => {
// Redundant sample. Do nothing or print a log.
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class RNStartupTimePackage implements ReactPackage {
private boolean enforceSingleInvocation;

public RNStartupTimePackage() {
this(false);
this(true);
}

/**
Expand Down