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

measure the rendering time of a component #24551

Closed
taioo opened this issue Apr 21, 2019 · 5 comments
Closed

measure the rendering time of a component #24551

taioo opened this issue Apr 21, 2019 · 5 comments
Labels
Bug Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@taioo
Copy link

taioo commented Apr 21, 2019

Hi react-native team,

I'm currently working on the performance analytical topic regarding react native. I should measure the rendering time of a component that we have. I found following way how to do this, but not sure if I'm on the right way.

Below you can see a simple Button Widget. I'm using here the component constructor as init function to count the start time and the componentDidMount() function, which will be called after the render/build is done to count the end time and print it out.

import React, { Component } from "react";
import {
  TouchableOpacity,
  Text,
  View,
  StyleSheet
} from "react-native";


class ButtonWithBackground extends Component {


  state = {
    start:'0',
};

  constructor(props) {
    super(props);
    this.state.start=Date.now();
  }


  componentDidMount() {

    console.log('%c######## RENDER time ButtonWithBackground:','background: red',(Date.now()-this.state.start));
  }

  render() {
    return (
      <TouchableOpacity onPress={this.props.onPress}>
        <View style={[styles.button, { backgroundColor: this.props.color }]}>
          <Text>
            press
          </Text>
        </View>

      </TouchableOpacity>

    );

  }

}

const styles = StyleSheet.create({
  button: {
    backgroundColor: 'blue',
    borderWidth: 1,
    borderColor: 'blue',
    borderRadius: 12,
    padding: 8,
    overflow: 'hidden',
    fontWeight: "bold",
    textAlign: "center",
    fontSize: 28
  }
});

export default ButtonWithBackground;

The results are different when I start the app on the (ios) emulator and If I just navigate to different UI that doesn't include the button and switch back.
Not sure how I should consider this in my results. Are there some options provided by react-native to control this?
The results are without coma because I'm using Date.now() . Maybe there is a better Timer object.

Best Regards,
taioo

@react-native-bot
Copy link
Collaborator

Thanks for submitting your issue. Can you take another look at your description and make sure the issue template has been filled in its entirety?

👉 Click here if you want to take another look at the Bug Report issue template.

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Resolution: Needs More Information labels Apr 21, 2019
@jeremy-deutsch
Copy link

I don't think this is a bug report. Have you tried the DevTools Profiler?

@JKCooper2
Copy link

https://github.com/jhen0409/react-native-debugger has the react devtools built in which can show render times, whats being updated, and why

@stale
Copy link

stale bot commented Aug 2, 2019

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 2, 2019
@stale
Copy link

stale bot commented Aug 9, 2019

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Aug 9, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Aug 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

5 participants