File size: 3,136 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# Performance
- React Docs: [Optimizing Performance](https://reactjs.org/docs/optimizing-performance.html)
- [Debugging React performance with React 16 and Chrome Devtools](https://building.calibreapp.com/debugging-react-performance-with-react-16-and-chrome-devtools-c90698a522ad)
- Chrome DevTools Docs: [Analyze Runtime Performance](https://developers.google.com/web/tools/chrome-devtools/rendering-tools/)
## Server Request Profiling
> [!NOTE]
> The profiler is temporarily disabled due to non-compatibility with the current Node version.
We've included [`v8-profiler-next`](https://www.npmjs.com/package/v8-profiler-next) which allows you to generate CPU profiles (including flamegraphs) for requests to the Calypso NodeJS server. This is helpful for finding functions which impact performance the most on a given route.
To use the profiler:
1. Run `USE_SERVER_PROFILER=true yarn start`.
2. Visit a url like `calypso.localhost:3000/themes`
3. After waiting a few extra seconds, a profile file is saved to "./profiles/$route/$route-$time.cpuprofile"
4. This profile can be viewed with VS Code's built-in profile viewer by clicking on the profile in VS Code's file explorer. If you click the flame icon in the upper-right corner, VS Code will prompt to install a flamegraph viewer extension as well.
Some notes:
- The behavior of the dev server can differ from production, and having the profiler enabled can reduce performance. While profiles should not be treated as a source of truth for absolute production performance, they are still useful for seeing _relative_ performance. (E.g. to find a function which takes relatively more time than other functions.)
- Any slash in the URL ("/") is changed to "\_" in the filename. So when you access the base route ("/"), the profile will be saved to "./profiles/\_/\_-$datetime.cpuprofile"
- Only one profile can be generated at a time. If you visit another route at the same time a profile is being generated for a different route, a new profile is _not_ created. However, since the CPU is a shared resource, the impact of visiting the second route at the same time will still be visible in the first route's profile.
- Requests to various static and dev resources are not profiled.
## Bundle Analysis
### Why is X bundled?
If you want to know why a certain module is bundled you can use `whybundled` to find out. See the following for an example on usage:
```sh
yarn run preanalyze-bundles
yarn run whybundled -- [module]
npn run whybundled -- is-my-json-valid
```
This should give you an overview on where this module got bundled and which file are requiring it:
```
MODULE is-my-json-valid
ββ imported: 13 times
ββ deps count: 5
ββ size: 19 KiB [for all included files]
ββ type: [direct]
ββ chunks: vendors~build
ββ locations:
β ββ ./node_modules/is-my-json-valid/
β
ββ files:
β ββ ./node_modules/is-my-json-valid/formats.js
β ββ ./node_modules/is-my-json-valid/index.js
β
ββ reasons:
ββ ./client/extensions/woocommerce/index.js + 439 modules 7:0-41 [harmony side effect evaluation]
ββ [...]
```
|