Skip to content

Commit 947fc8c

Browse files
authored
Update readme to reflect the new default sampling strategy
1 parent b2334ea commit 947fc8c

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

README.md

+18-21
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ If you know a better way to measure startup time (in a module), let me know or b
1414

1515
### Mostly automatic installation
1616

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

1919
Otherwise, run
2020

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

2323
### Manual linking installation
2424

25+
<details>
26+
<summary>Show manual installation steps</summary>
27+
2528
1. Open `./android/settings.gradle`, add this:
2629

2730
```gradle
@@ -44,20 +47,20 @@ import com.github.doomsower.RNStartupTimePackage;
4447
// Define package
4548
new RNStartupTimePackage()
4649
```
50+
</details>
51+
4752

4853
## Usage
4954

5055
Render startup time badge somewhere on your first screen:
5156

5257
```jsx
5358
import { StartupTime } from 'react-native-startup-time';
54-
...
5559

5660
<StartupTime
57-
ready={true /* optional, defaults to true */}
58-
style={styles.startupTime /* optional*/}
61+
ready={true /* optional, defaults to true */}
62+
style={styles.startupTime /* optional*/}
5963
/>
60-
6164
```
6265

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

74-
### Ensuring purity of your analytics data
77+
_The following sections are applicable to Android only_
78+
79+
### Single-Sampling
80+
81+
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).
7582

76-
_This section is applicable to Android only_
83+
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.
7784

78-
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.
85+
#### Disabling Single-Sampling:
7986

80-
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.
87+
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.
8188

82-
To enforce single-sampling strategy, create your package using constructor with parameter `true`:
89+
To disable single-sampling strategy, create your package using constructor with parameter `false`:
8390
```java
8491
// Define package
85-
new RNStartupTimePackage(true)
92+
new RNStartupTimePackage(false)
8693
```
87-
then sample the startup time with catching the redundant invocation error:
88-
```jsx
89-
// when you app is ready:
90-
getTimeSinceStartup().then((time) => {
91-
// Initial sample. Collect it for your analytics.
92-
})
93-
.catch((e) => {
94-
// Redundant sample. Do nothing or print a log.
95-
});
96-
```

0 commit comments

Comments
 (0)