Skip to content

update react perf docs (#8060) and (#6174) #8236

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

Merged
merged 2 commits into from
Feb 7, 2017
Merged

Conversation

dhyey35
Copy link
Contributor

@dhyey35 dhyey35 commented Nov 8, 2016

Number 11 on checklist of issue #8060 -

Added example, console screenshot and link to live demo where user can open console and call Perf methods.


//If Perf is not accessible from console i.e throws RefrenceError:
//Perf is not defined, create a global
window.Perf = Perf;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is something we want to tell everyone to do, is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this tutorial I am using only one file but in real projects developers use bable and webpack or other such tools. If we import Perf ES6 style in any file of our project we have to make it global to access it from console and @gaearon has mentioned it in issue #6174 . So I think we should let developers know solution to a common problem beforehand. What do you think ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has been mentioned in the solution of issue #6174 . So I think it should be included so developers know how to solve it when they run into reference error.

@@ -14,6 +14,10 @@ next: test-utils.html
import Perf from 'react-addons-perf' // ES6
var Perf = require('react-addons-perf') // ES5 with npm
var Perf = React.addons.Perf; // ES5 with react-with-addons.js

//If Perf is not accessible from console i.e throws RefrenceError:
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpicks: spaces after //, Refrence misspelled

@@ -32,7 +36,7 @@ See these articles by the [Benchling Engineering Team](http://benchling.engineer

If you're benchmarking or seeing performance problems in your React apps, make sure you're testing with the [minified production build](/react/downloads.html). The development build includes extra warnings that are helpful when building your apps, but it is slower due to the extra bookkeeping it does.

However, the perf tools described on this page only work when using the development build of React. Therefore, the profiler only serves to indicate the _relatively_ expensive parts of your app.
However, the perf tools described on this page only work when using the development build of React. If you set NODE_ENV to _production_ than it will not work. Therefore, the profiler only serves to indicate the _relatively_ expensive parts of your app.
Copy link
Contributor

Choose a reason for hiding this comment

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

NODE_ENV is only applicable when compiling yourself - you might be using a CDN version. So I think this sentence is better just left out, the right way to refer to this is "using the development build" rather than "setting NODE_ENV".

@@ -56,6 +60,33 @@ The following methods use the measurements returned by [`Perf.getLastMeasurement

* * *

## Example Usage:
Copy link
Contributor

Choose a reason for hiding this comment

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

no : needed

@@ -56,6 +60,33 @@ The following methods use the measurements returned by [`Perf.getLastMeasurement

* * *

## Example Usage:

We will take the comments example from old official tutorial. The example code is availabe on [github](https://github.com/dhyey35/react-example-for-performance/blob/master/public/scripts/example.js).
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than referring to "the old official tutorial" how about just having a little bit of example code and then linking to somewhere that it's available as a html file where people can just drop into dev tools. It could be in the assets directory in the react website, I think that would make sense because we put some other html stuff there too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where should I put my code in order to get it into assets dir on react website as I dont have access to it ? Examples directory of repo ?

//Using react-with-addons.js in ES5
var Perf = React.addons.Perf;

var Comment = React.createClass({
Copy link
Contributor

Choose a reason for hiding this comment

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

our example code we're using ES6 for now - could you make this the same style as the other docs?

rawMarkup: function() {
var md = new Remarkable();
var rawMarkup = md.render(this.props.children.toString());
return { __html: rawMarkup };
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you avoid using this dangerous html stuff in example code?


![](/react/img/docs/addons-perf.png)

A **Live Example** of the above code is available on [react-example-for-performance](https://react-example-for-performance.herokuapp.com/)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's best to avoid dependencies on new backends, especially a one-off herokuapp instance. Perhaps this could just be a static file on the react website itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where should I put the code to get it into assets dir of react website ?

Copy link

@davidwparker davidwparker left a comment

Choose a reason for hiding this comment

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

Comment about inconsistent code spacing.


const Comment = (props) => {
return (
<div className="comment">

Choose a reason for hiding this comment

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

Minor: Looks like you have some inconsistent spacing here. (sometimes 2, sometimes 3)...

@dhyey35
Copy link
Contributor Author

dhyey35 commented Dec 26, 2016

@davidwparker Fixed the inconsistent spacing issue. @lacker can you please tell me where should i put my example code as to get it into assets directory of react website which you mentioned in above comment

It could be in the assets directory in the react website, I think that would make sense because we put some other html stuff there too.

@gaearon
Copy link
Collaborator

gaearon commented Jan 4, 2017

@lacker Can you please follow up on this?

@lacker
Copy link
Contributor

lacker commented Jan 11, 2017

Hey, sorry I had a bit of email bankruptcy over the holiday break. Assets are in their own directories under docs, so js assets are in https://github.com/facebook/react/tree/master/docs/js for example and they appear on the site under URLs like https://facebook.github.io/react/js/remarkable.min.js . There is a bunch of misc example-type stuff in there so I think a dependency would be better in there than on a separate site.

<span>{props.children.toString()}</span>
</div>
)
}
Copy link

Choose a reason for hiding this comment

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

@dhyey35 How about dropping return?

const Comment = props => (
    <div className="comment">
        <h2 className="commentAuthor">
            {props.author}
        </h2>
        <span>{props.children.toString()}</span>
    </div>
);

document.getElementById('content')
);
```
Open the developer console in the browser and type `Perf.start()` than followed by the action you want to monitor eg: submitting a form. Than type `Perf.stop()` in the console and than type `Perf.getLastMeasurements()` to get the measurements .See the Reference below for more methods.
Copy link

Choose a reason for hiding this comment

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

"than" vs. "then"

document.getElementById('content')
);
```
Open the developer console in the browser and type `Perf.start()` than followed by the action you want to monitor eg: submitting a form. Than type `Perf.stop()` in the console and than type `Perf.getLastMeasurements()` to get the measurements .See the Reference below for more methods.
Copy link

Choose a reason for hiding this comment

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

the measurements .See the

Spacing in text

@@ -14,6 +14,10 @@ next: test-utils.html
import Perf from 'react-addons-perf' // ES6
var Perf = require('react-addons-perf') // ES5 with npm
var Perf = React.addons.Perf; // ES5 with react-with-addons.js

// If Perf is not accessible from console i.e throws ReferenceError:
// Perf is not defined, create a global
Copy link

Choose a reason for hiding this comment

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

Question for understanding: Should it be available globally by default? When will it be available and when not? What circumstances trigger the different states?

@dhyey35 dhyey35 force-pushed the perf-docs branch 3 times, most recently from fd1b36f to 479de22 Compare January 29, 2017 12:56
@dhyey35
Copy link
Contributor Author

dhyey35 commented Jan 29, 2017

@andys8 I have made the changes you suggested. Can you please let me know if they are okay or need any changes ?

@lacker I pushed the code to docs/css/perf-tutorial.css , docs/tutorial/perf-tutorial.html , docs/_js/perf-tutorial.min.js as docs/js is in the .gitignore file. Have I placed them correctly ?

@andys8
Copy link

andys8 commented Jan 29, 2017

@dhyey35 Great, i appreciate your changes.

@@ -57,6 +62,34 @@ The following methods use the measurements returned by [`Perf.getLastMeasurement

* * *

## Example Usage

We will take the [simple example]() of a form which can be used to submit comments and then listing all comments. The example code is availabe on [github](https://github.com/dhyey35/react-example-for-performance/blob/master/public/scripts/example.js).
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like one of the links is missing here?

@lacker
Copy link
Contributor

lacker commented Feb 2, 2017

Hmm, the location of these files seems kind of weird - you are putting them through the site's build system when really you don't want any of that, you just want a static file. docs/tutorial does not seem right because the other stuff there is markdown. How about just sticking it in the downloads directory as a single file, similar to single-file-example.html ?

@dhyey35
Copy link
Contributor Author

dhyey35 commented Feb 6, 2017

@lacker I removed the missing link which wasn't needed and made a single html file in downloads/perf-tutorial.html

Small stuff
@lacker lacker merged commit 994a0c8 into facebook:master Feb 7, 2017
@lacker
Copy link
Contributor

lacker commented Feb 7, 2017

Awesome, looks good! Thank you for writing this up!

@dhyey35
Copy link
Contributor Author

dhyey35 commented Feb 11, 2017

@lacker @gaearon @andys8 @davidwparker @zpao Thanks for helping me throughout the way and giving opportunity to beginners to contribute to such a big project. This was my first PR to a big project. You guys are awesome.

@lacker
Copy link
Contributor

lacker commented Feb 13, 2017

Thanks for making the world a slightly-better-documented place ;-)

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

I appreciate the effort but I think this needs to be reworked to better match the rest of the docs. I'm going to revert this specific PR but I'll be happy to review a follow-up that addresses these specific concerns.

We will take simple example of a form which can be used to submit comments and then listing all comments. The example code is [available on GitHub](https://github.com/dhyey35/react-example-for-performance/blob/master/public/scripts/example.js).

```javascript
import { Component } from 'react'
Copy link
Collaborator

Choose a reason for hiding this comment

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

This import is unused.

import { Component } from 'react'
import Perf from 'react-addons-perf'

const Comment = (props) => (
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't use this style of declaring components anywhere in the docs. We used function everywhere because it's easier to understand for people new to ES6.

<span>{props.children.toString()}</span>
</div>
)
//code...
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this comment represent? I don't think it makes the example more clear.

//code...

ReactDOM.render(
<CommentBox />,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This component is named CommentBox but the component declared above is called Comment. What is the reason for the discrepancy?

document.getElementById('content')
);
```
Open the developer console in the browser and type `Perf.start()`. Then perform the action you want to monitor, like submitting a form. Finally, type `Perf.stop()` and `Perf.getLastMeasurements()` to get the measurements. See the Reference below for more methods.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The user reading this will likely miss the initial window.Perf assignment because it's in another code snippet, and will get that error about Perf being undefined.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perf.getLastMeasurements() is an extremely low level method and gives information that has very little value to the user unless they know how to interpret it. This is definitely not what we should be suggesting to the user as an introductory example.

{
author: "Kevin Lacker",
id: 1,
text: "I Love React"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we could have better more appropriate text than praising ourselves. 😉

@gaearon
Copy link
Collaborator

gaearon commented Feb 13, 2017

Apologies for reverting—I want to get this in, but I just don't think it works as is. Happy to review this if you address the requested changes.

gaearon pushed a commit that referenced this pull request Feb 13, 2017
* update react perf docs issue 8060 and 6174

* Grammar

Small stuff

(cherry picked from commit 994a0c8)
@dhyey35
Copy link
Contributor Author

dhyey35 commented Feb 14, 2017

@gaearon No problems, will address the requested changes. Should I submit a new PR or restore my branch perf-docs and push to it ?

@gaearon
Copy link
Collaborator

gaearon commented Feb 14, 2017

A new PR would be fine. 👍
Please tag me in it and I’ll review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants