Skip to content

Commit e99366b

Browse files
committed
refactor: update measure readme
1 parent 646ae56 commit e99366b

File tree

1 file changed

+126
-14
lines changed
  • packages/cpu-prof/docs/case-study--nx-graph-time

1 file changed

+126
-14
lines changed
Lines changed: 126 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,155 @@
11
# Case Study — Nx graph time
22

3-
## Measured graphs
3+
4+
## Tools and Setup
5+
6+
### Setup Detection
7+
8+
We use commands to capture the setup specification:
9+
- `nx report` - to capture the Nx, Node.js, and OS versions.
10+
- `nx reset` - to reset the Nx daemon and clear the cache before running measurements.
11+
12+
### Environment
13+
14+
We disable the Nx daemon and the Nx cache to ensure consistent measurements:
15+
16+
- `NX_DAEMON=false` - Disables the Nx daemon, which can cache results and affect performance measurements.
17+
- `NX_CACHE=false` - Disables the Nx computation cache, ensuring that all computations are performed fresh without cached results.
18+
- `NX_TUI=false` - Disables the Nx TUI (Text User Interface) to avoid any potential interference with performance measurements.
19+
20+
### CPU Profiling
21+
22+
We use the native Node.js CPU profiling capabilities through the `--cpu-prof` and `--cpu-prof-dir` flags.
23+
The tool [@push-based/cpu-prof](https://www.npmjs.com/package/@push-based/cpu-prof) 🚀 provides a convenient CLI to run commands with CPU profiling enabled and to merge multiple CPU profiles into one.
24+
25+
## Measurements
426

527
Use native Node.js CPU profiling to analyze where time is spent when calculating Nx graphs.
628

7-
### Project Graph
29+
The following commands are executed from the root of a Nx workspace:
30+
- `npx nx graph --file=nx-project-graph.json` - project graph generation
31+
- `npx nx graph --groupByFolder --file=nx-project-graph-grouped.json` - project graph with grouped folders
32+
- Remove plugins form nx.json, then run `npx nx graph --file=nx-project-graph-no-plugins.json` - project graph without plugins
33+
- `npx nx graph --view=tasks --targets=<targets> --file=nx-task-graph-build.json` - task graph for specific target
34+
- `npx nx graph --affected --base=main --file=/tmp/nx-affected-graph-main.json` - affected graph calculation for specified base
35+
36+
### Project Graph (nx graph)
837

9-
Save setup specification:
38+
1. Save setup specification:
1039

1140
```bash
12-
nx report > ./profiles/nx-show-projects/nx-report.md
41+
mkdir -p ./profiles/nx-project-graph && \
42+
nx reset && nx report > ./profiles/nx-project-graph/nx-report.md
1343
```
1444

15-
Measure the project graph creation:
45+
2. Measure the project graph creation:
1646

1747
```bash
1848
# Prerequisite (once): install local deps so ./node_modules/.bin/nx exists
1949
NX_DAEMON=false NX_CACHE=false \
2050
npx -y @push-based/cpu-prof \
21-
--cpu-prof-dir ./profiles/nx-show-projects \
22-
node ./node_modules/nx/bin/nx.js show projects --json
51+
--cpu-prof-dir ./profiles/nx-project-graph \
52+
node ./node_modules/nx/bin/nx.js graph --file=nx-project-graph.json
53+
```
54+
55+
56+
### Project Graph (grouped by folder)
57+
58+
1. Save setup specification:
59+
60+
```bash
61+
mkdir -p ./profiles/nx-project-graph-grouped && \
62+
nx reset && nx report > ./profiles/nx-project-graph-grouped/nx-report.md
63+
```
64+
65+
2. Measure the project graph creation with grouped folders:
66+
67+
```bash
68+
# Prerequisite (once): install local deps so ./node_modules/.bin/nx exists
69+
NX_DAEMON=false NX_CACHE=false \
70+
npx -y @push-based/cpu-prof \
71+
--cpu-prof-dir ./profiles/nx-project-graph-grouped \
72+
node ./node_modules/nx/bin/nx.js graph --groupByFolder --file=nx-project-graph-grouped.json
73+
```
74+
75+
76+
### Project Graph (no plugins)
77+
78+
1. Save setup specification:
79+
80+
```bash
81+
mkdir -p ./profiles/nx-project-graph-no-plugins && \
82+
nx reset && nx report > ./profiles/nx-project-graph-no-plugins/nx-report.md
83+
```
84+
85+
2. Measure the project graph creation without plugins:
86+
87+
```bash
88+
# Prerequisite (once): install local deps so ./node_modules/.bin/nx exists
89+
# Before running, remove plugins from nx.json
90+
NX_DAEMON=false NX_CACHE=false \
91+
npx -y @push-based/cpu-prof \
92+
--cpu-prof-dir ./profiles/nx-project-graph-no-plugins \
93+
node ./node_modules/nx/bin/nx.js graph --file=nx-project-graph-no-plugins.json
94+
```
95+
96+
97+
### Task Graph for specific target(s)
98+
99+
1. Save setup specification:
100+
101+
```bash
102+
mkdir -p ./profiles/nx-task-graph-build && \
103+
nx reset && nx report > ./profiles/nx-task-graph-build/nx-report.md
104+
```
105+
106+
2. Measure the task graph creation for specific target(s):
107+
108+
```bash
109+
# Prerequisite (once): install local deps so ./node_modules/.bin/nx exists
110+
NX_DAEMON=false NX_CACHE=false \
111+
npx -y @push-based/cpu-prof \
112+
--cpu-prof-dir ./profiles/nx-task-graph-build \
113+
node ./node_modules/nx/bin/nx.js graph --view=tasks --targets=<targets> --file=nx-task-graph-build.json
23114
```
24115

25-
### Task Graph
26116

27-
Save setup specification:
117+
### Affected Graph (base=main)
118+
119+
1. Save setup specification:
28120

29121
```bash
30-
nx report > ./profiles/nx-show-project/nx-report.md
122+
mkdir -p ./profiles/nx-affected-graph-main && \
123+
nx reset && nx report > ./profiles/nx-affected-graph-main/nx-report.md
31124
```
32125

33-
Measure the task graph creation:
126+
2. Measure the affected graph calculation for the specified base:
34127

35128
```bash
36129
# Prerequisite (once): install local deps so ./node_modules/.bin/nx exists
37130
NX_DAEMON=false NX_CACHE=false \
38131
npx -y @push-based/cpu-prof \
39-
--cpu-prof-dir ./profiles/nx-show-project \
40-
node ./node_modules/nx/bin/nx.js show project <project-name> --json
132+
--cpu-prof-dir ./profiles/nx-affected-graph-main \
133+
node ./node_modules/nx/bin/nx.js graph --affected --base=main --file=/tmp/nx-affected-graph-main.json
134+
```
135+
136+
---
137+
138+
### Project Graph
139+
140+
1. Save setup specification:
141+
142+
```bash
143+
mkdir -p ./profiles/nx-show-projects && \
144+
nx reset && nx report > ./profiles/nx-show-projects/nx-report.md
41145
```
42146

43-
|
147+
2. Measure the project graph creation:
148+
149+
```bash
150+
# Prerequisite (once): install local deps so ./node_modules/.bin/nx exists
151+
NX_DAEMON=false NX_CACHE=false \
152+
npx -y @push-based/cpu-prof \
153+
--cpu-prof-dir ./profiles/nx-show-projects \
154+
node ./node_modules/nx/bin/nx.js show projects --json
155+
```

0 commit comments

Comments
 (0)