Coder Social home page Coder Social logo

doomsower / react-native-startup-time Goto Github PK

View Code? Open in Web Editor NEW
114.0 3.0 13.0 452 KB

measure startup time of your react-native app

License: MIT License

JavaScript 23.71% Java 26.93% Ruby 13.61% Objective-C 26.23% Starlark 9.52%
react-native benchmark debug profiling startup measurement optimization

react-native-startup-time's Introduction

react-native-startup-time

This module helps you to measure your app launch time. It is measured from the earliest point in time available to the native module, that is the module's initialization. When getTimeSinceStartup is called on JS side, you'll get a promise which resolves with difference between these two moments in ms. This is not very accurate, but should give you good enough base for further optimizations.

On iOS time measurement is based on this article. On Android SystemClock.uptimeMills is used.

As far as I know, there's no way to programmatically obtain time passed since the moment when user taps on app icon. For this you have to use native dev tools. On Android this module will call reportFullyDrawn so you can inspect adb logs.

If you know a better way to measure startup time (in a module), let me know or better shoot a PR.

Getting started

$ yarn add react-native-startup-time

Mostly automatic installation

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

Show manual installation steps
  1. Open ./android/settings.gradle, add this:
include ':react-native-startup-time'
project(':react-native-startup-time').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-startup-time/android')
  1. Open ./android/app/build.gradle, add this:
implementation project(':react-native-startup-time')
  1. In MainApplication.java, add this:
// Import
import com.github.doomsower.RNStartupTimePackage;

// Define package
new RNStartupTimePackage()

Usage

Render startup time badge somewhere on your first screen:

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

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

Or use imperative call:

import { getTimeSinceStartup } from 'react-native-startup-time';

// when you app is ready:
getTimeSinceStartup().then((time) => {
  console.log(`Time since startup: ${time} ms`);
});

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.

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.

Disabling Single-Sampling:

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 disable single-sampling strategy, create your package using constructor with parameter false:

// Define package
new RNStartupTimePackage(false)

react-native-startup-time's People

Contributors

aaulthudl avatar andreicalazans avatar arryanggaputra avatar christianchown avatar christianchownsan avatar doomsower avatar john-y-pazekha avatar lucasfeijo avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-startup-time's Issues

Issue with Android metrics when OS kills activity

Hi!

We've discovered another issue where we're seeing unrealistic high numbers for Android (we're talking multiple minutes).

If I understand the lifecycle mechanics of Android correctly, I believe there will be cases where the app is pushed to the background and the Android OS will clean up the Activity context while the Application context is still available. When the app is later returned to the foreground, the Activity context (which will execute any JavaScript calling the API for getting startup time data) gets re-created. Since the Application context was still available, the new calculation will be based on the old timestamp generated when the Application context was created.

This means that the concept of startup time is a bit more complex in the Android domain compared to on iOS. One need to distinguish between "hot" case (Application context is already available, Activity gets created) and "cold" case (Application context needs to be created, Activity gets created). The "unified" way to treat startup time between platforms would be to only care about the "cold" case.

One way of resolving this could be to only calculate and resolve the value once from the native side. Subsequent calls would then either return the same value or reject the call (allowing conditional reporting on the JavaScript side of things).

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

How can I properly use this?

I am using vscode. I don't use android studio at all, but the instructions are strictly for android studio it seems. I didn't see anyone who use android studio for that anyway. You don't even use anything related with android studio much in react. You don't need it. This is javascript anyway, android studio has nothing to do with this. Even in youtube tutorials none uses android studio for that.

Anyway here s what I did and what didn't work.

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

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

console.log(a)


import { getTimeSinceStartup } from 'react-native-startup-time';

// when you app is ready:
getTimeSinceStartup().then((time) => {
console.log(Time since startup: ${time} ms);
});
a=getTimeSinceStartup()

console.log(a)


Both returns null. I tried various things, its just a small thing I didn't expect it give so much errors at start. That's why I think a little more documentation would be good. I even copy pasted that and it still doesn't work.

Issue with Android KitKat

Hi!
We tried out the package while implementing performance instrumentation but ran into issues with the following exception:
uid xxxxx does not have android.permission.UPDATE_DEVICE_STATS.

Affected OS versions seem to be KitKat (as has been reported by other users of reportFullyDrawn()) and when going through the implementation, I noticed the check for that specific range of versions. However, the check seem to include KitKat - should it not be
>= Build.VERSION_CODES.LOLLIPOP
instead?

Thanks in advance!

Application load time issue with iOS ver 15 or above

We have been facing lots of unrealistic app load times in our mobile application for iOS users. As per our investigation, it is commonly occurring in the iOS version 15 or above. We have also tested with the lower version of iOS but it was working fine for them. I think we need to make some updates to the package as the latest version of the package is 2.0.0 which was launched 10 months ago and iOS 15 was launched on 20th Sep 2021. Could you please suggest?

Can not run in vs code, and instructions not clear enough

I tried everything but this just doesn't work. Your docs isn't very clear. No good example aswell. Tried putting that function into a variable but it doesn't work. Console log doesn't work. Nothing works. I literally wasted a lot of time with this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.