Skip to content

Commit 8f722c3

Browse files
authored
docs: guide bounded react devtools profiling (#548)
1 parent c155072 commit 8f722c3

6 files changed

Lines changed: 64 additions & 20 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Run:
170170
- Capture a baseline `snapshot -i`, screenshot, and `perf --json` sample.
171171
- Exercise Home, Catalog, product detail, Checkout, and Settings. Re-snapshot after each mutation and use refs/selectors from fresh snapshots.
172172
- Capture at least one overlay-ref screenshot, one normal screenshot, one short video recording for a meaningful flow, logs marks around any issue, and trace output if a runtime symptom needs diagnostics.
173-
- Run focused performance checks: compare `perf --json` before and after a navigation or form flow; if React DevTools connects, capture profile slow/rerender output. If it cannot connect, include the status and continue.
173+
- Run focused performance checks: compare `perf --json` before and after a navigation or form flow; if React DevTools connects, use one bounded first-pass profile survey (`slow --limit 5`, `rerenders --limit 5`, and `timeline --limit 20` only when timing matters), then drill into a specific `@c` ref with `profile report`. If it cannot connect, include the status and continue.
174174
- Close the session so the `.ad` replay is written.
175175
176176
Report:

src/utils/__tests__/args.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ test('usageForCommand resolves workflow help topic', () => {
897897
assert.match(help, /metro prepare --kind expo/);
898898
assert.match(help, /help react-devtools/);
899899
assert.match(help, /help react-native/);
900+
assert.doesNotMatch(help, /agent-device react-devtools profile/);
900901
});
901902

902903
test('workflow help keeps common copyable command forms', () => {
@@ -975,7 +976,14 @@ test('usageForCommand resolves react-devtools help topic', () => {
975976
);
976977
assert.match(help, /render causes and changed props\/state\/hooks/);
977978
assert.match(help, /logs clear --restart before the first logs mark/);
979+
assert.match(help, /one bounded first-pass survey/);
980+
assert.match(help, /profile slow --limit 5 once/);
981+
assert.match(help, /profile rerenders --limit 5 once/);
982+
assert.match(help, /profile timeline --limit 20 only when commit timing matters/);
983+
assert.match(help, /Do not repeatedly raise broad profile slow limits/);
984+
assert.match(help, /profile report unless you have a specific target/);
978985
assert.match(help, /agent-device logs mark "before catalog search"/);
986+
assert.match(help, /agent-device react-devtools profile timeline --limit 20/);
979987
assert.match(help, /Do not write agent-devtools/);
980988
assert.match(help, /agent-device network dump --include headers/);
981989
assert.match(help, /@c refs reset after reload\/remount/);

src/utils/command-schema.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,6 @@ React Native dev loop:
346346
If apps lookup misses the project but shows Expo Go/dev-client and a project URL is available, open the URL/host shell; if no URL is available, ask instead of inventing an app id.
347347
Expo Dev Client/development builds: open the installed dev-client app id/name; if a dev-client URL is provided, open that URL next. For Metro setup use metro prepare --kind expo.
348348
349-
React DevTools minimum loop:
350-
Keep the agent-device react-devtools prefix on every React DevTools command:
351-
agent-device react-devtools status
352-
agent-device react-devtools wait --connected
353-
agent-device react-devtools profile start
354-
interact with normal agent-device commands
355-
agent-device react-devtools profile stop
356-
agent-device react-devtools profile slow --limit 5
357-
agent-device react-devtools profile rerenders --limit 5
358-
359349
Escalate:
360350
help debugging logs, network, alerts, traces, flaky runtime failures
361351
help react-devtools React Native performance, profiling, props/state/hooks, slow renders, rerenders
@@ -447,15 +437,16 @@ Profiling loop:
447437
3. Start profiling immediately before the interaction.
448438
4. Drive the interaction with normal agent-device commands and mark before/after the repro when timing matters.
449439
5. Stop profiling.
450-
6. Inspect slow components and rerenders.
451-
7. Use profile report @cN for render causes and changed props/state/hooks; use get component @cN for current props/state/hooks.
440+
6. Make one bounded first-pass survey: profile stop for the summary, profile slow --limit 5 once, profile rerenders --limit 5 once, and profile timeline --limit 20 only when commit timing matters.
441+
7. Use profile report @cN for targeted render causes and changed props/state/hooks; use get component @cN for current props/state/hooks.
452442
453443
Rules:
454444
Every React DevTools command is an agent-device subcommand: agent-device react-devtools ...
455445
Do not write agent-devtools, agent-react-devtools, or bare react-devtools commands in final command plans.
456446
Start with get tree --depth 3 or find <name>; use find --exact when fuzzy results are noisy.
457447
@c refs reset after reload/remount. After reload, wait --connected and inspect again.
458448
Keep the profile window narrow; unrelated navigation makes render data noisy.
449+
Do not repeatedly raise broad profile slow limits such as --limit 50, --limit 200, or --limit 500. Drill into a specific @c ref with profile report unless you have a specific target that needs more rows.
459450
For network evidence, use agent-device network dump --include headers; headers is not a positional argument.
460451
For cross-platform validation with explicit device selectors, prefer isolated --state-dir and restart react-devtools between platforms.
461452
Remote Android and iOS bridge runs normally through agent-device react-devtools; the CLI keeps the needed local service tunnel alive until agent-device react-devtools stop or disconnect. Expo support depends on the SDK's bundled React Native runtime.
@@ -472,6 +463,7 @@ Example:
472463
agent-device react-devtools profile stop
473464
agent-device react-devtools profile slow --limit 5
474465
agent-device react-devtools profile rerenders --limit 5
466+
agent-device react-devtools profile timeline --limit 20
475467
agent-device react-devtools profile report @c5
476468
agent-device network dump --include headers
477469

test/skillgym/suites/agent-device-smoke-suite.ts

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ const RAW_COORDINATE_TARGET =
203203
/(?:^|\n)(?:agent-device\s+)?(?:click|fill|press)\s+-?\d+(?:\.\d+)?\s+-?\d+(?:\.\d+)?/i;
204204
const PSEUDO_ASSERTION_COMMAND = /(?:^|\n)\s*(?:assert|assertVisible|waitFor|waitForText)\b/i;
205205
const COMPACT_RECT_SNAPSHOT = /snapshot\b(?=[^\n]*(?:-c\b|--compact\b))(?=[^\n]*(?:--json|--raw))/i;
206+
const BOUNDED_PROFILE_SLOW = /react-devtools\s+profile\s+slow\b[^\n]*--limit\s+(?:5|10)\b/i;
207+
const BOUNDED_PROFILE_RERENDERS =
208+
/react-devtools\s+profile\s+rerenders\b[^\n]*--limit\s+(?:5|10)\b/i;
209+
const BOUNDED_PROFILE_TIMELINE =
210+
/react-devtools\s+profile\s+timeline\b[^\n]*--limit\s+(?:10|20)\b/i;
211+
const BROAD_PROFILE_SLOW_LIMIT =
212+
/react-devtools\s+profile\s+slow\b[^\n]*--limit\s+(?:[5-9]\d|[1-9]\d{2,})\b/i;
206213
const IOS_EXPO_GO_OPEN =
207214
/(?:^|\n)(?:agent-device\s+)?open\s+["']Expo Go["']\s+["']?exp:\/\/127\.0\.0\.1:8081["']?/i;
208215

@@ -1124,10 +1131,36 @@ const SKILL_GUIDANCE_CASES: Case[] = [
11241131
plannedCommand('react-devtools profile start'),
11251132
/catalog-search/i,
11261133
plannedCommand('react-devtools profile stop'),
1127-
plannedCommand('react-devtools profile slow'),
1128-
plannedCommand('react-devtools profile rerenders'),
1134+
BOUNDED_PROFILE_SLOW,
1135+
BOUNDED_PROFILE_RERENDERS,
11291136
],
1130-
forbiddenOutputs: [plannedCommand('snapshot'), plannedCommand('perf')],
1137+
forbiddenOutputs: [
1138+
plannedCommand('snapshot'),
1139+
plannedCommand('perf'),
1140+
BROAD_PROFILE_SLOW_LIMIT,
1141+
],
1142+
}),
1143+
makeCase({
1144+
id: 'react-devtools-bounded-profile-survey',
1145+
contract: [
1146+
'App name: Agent Device Tester',
1147+
'React Native DevTools is connected',
1148+
'Interaction to profile: expand the checkout totals panel',
1149+
'Totals panel selector: id="checkout-totals"',
1150+
'Need a compact performance report with initial summary, slow components, rerender counts, and commit timing',
1151+
'Do not over-fetch broad profile tables while looking for offenders',
1152+
],
1153+
task: 'Plan a bounded first-pass React DevTools profile workflow for the checkout totals interaction.',
1154+
outputs: [
1155+
plannedCommand('react-devtools wait'),
1156+
plannedCommand('react-devtools profile start'),
1157+
/checkout-totals/i,
1158+
plannedCommand('react-devtools profile stop'),
1159+
BOUNDED_PROFILE_SLOW,
1160+
BOUNDED_PROFILE_RERENDERS,
1161+
BOUNDED_PROFILE_TIMELINE,
1162+
],
1163+
forbiddenOutputs: [BROAD_PROFILE_SLOW_LIMIT],
11311164
}),
11321165
makeCase({
11331166
id: 'react-devtools-exact-component-inspect',
@@ -1192,11 +1225,17 @@ const SKILL_GUIDANCE_CASES: Case[] = [
11921225
/(?:5000|10000|12000|15000|20000)/i,
11931226
/logs mark\b[^\n]*(?:after|end|verified|diagnostics|loaded)/i,
11941227
plannedCommand('react-devtools profile stop'),
1195-
plannedCommand('react-devtools profile slow'),
1196-
plannedCommand('react-devtools profile rerenders'),
1228+
BOUNDED_PROFILE_SLOW,
1229+
BOUNDED_PROFILE_RERENDERS,
11971230
/network dump\b[^\n]*(?:--include headers|\bheaders\b|\ball\b)/i,
11981231
],
1199-
forbiddenOutputs: [RAW_COORDINATE_TARGET, /cat .*log/i, /alert wait/i, /agent-devtools/i],
1232+
forbiddenOutputs: [
1233+
RAW_COORDINATE_TARGET,
1234+
/cat .*log/i,
1235+
/alert wait/i,
1236+
/agent-devtools/i,
1237+
BROAD_PROFILE_SLOW_LIMIT,
1238+
],
12001239
}),
12011240
makeCase({
12021241
id: 'gesture-swipe-carousel',

website/docs/docs/commands.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,16 @@ agent-device react-devtools profile start
594594
agent-device react-devtools profile stop
595595
agent-device react-devtools profile slow --limit 5
596596
agent-device react-devtools profile rerenders --limit 5
597+
agent-device react-devtools profile timeline --limit 20
598+
agent-device react-devtools profile report @c5
597599
```
598600

599601
- `react-devtools` dynamically runs pinned `agent-react-devtools@0.4.0` through npm and passes arguments through 1:1.
600602
- The first run may download the pinned package from npm; later runs can reuse the npm cache.
601603
- `agent-device` global flags work before or after `react-devtools`. Use `--` before downstream flags only when they intentionally share an `agent-device` global flag name.
602604
- Use it when a React Native workflow needs component hierarchy, props, state, hooks, render causes, slow components, or re-render counts.
605+
- For profiling, keep the window narrow and make one bounded first-pass survey: use the `profile stop` summary, run `profile slow --limit 5` and `profile rerenders --limit 5` once, add `profile timeline --limit 20` only when commit timing matters, then drill into a specific `@c` ref with `profile report`.
606+
- Do not repeatedly raise broad `profile slow` limits such as `--limit 50`, `--limit 200`, or `--limit 500` unless you have a specific target that needs more rows.
603607
- Keep using `snapshot`, `press`, `fill`, `logs`, `network`, and `perf` for device/app runtime evidence. Use `react-devtools` for React internals.
604608
- For React Native apps, overlays, Metro/Fast Refresh blockers, and routing to React DevTools or debugging evidence, start with `agent-device help react-native`.
605609
- On Android, permission prompts are visible UI; use `snapshot -i` and press visible `Allow`/`Deny` controls instead of `alert wait`. Do not use `settings permission` to answer a dialog already on screen; reserve it for setup or resetting permission state before a flow.

website/docs/docs/debugging-profiling.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ agent-device react-devtools profile start
2626
agent-device react-devtools profile stop
2727
agent-device react-devtools profile slow --limit 5
2828
agent-device react-devtools profile rerenders --limit 5
29+
agent-device react-devtools profile timeline --limit 20
2930
agent-device react-devtools profile report @c5
3031
```
3132

3233
`agent-device` remains centered on the device and app runtime layer. The `react-devtools` command dynamically runs pinned `agent-react-devtools` commands for React internals.
3334

34-
For React Native apps, overlays, Metro/Fast Refresh blockers, and routing to React DevTools or debugging evidence, start with `agent-device help react-native`. For slow-flow investigations, combine `help react-devtools` for the narrow React profile window with `help debugging` for log markers, network evidence, traces, and perf samples.
35+
For React Native apps, overlays, Metro/Fast Refresh blockers, and routing to React DevTools or debugging evidence, start with `agent-device help react-native`. For slow-flow investigations, combine `help react-devtools` for the narrow React profile window with `help debugging` for log markers, network evidence, traces, and perf samples. Make one bounded first-pass survey with the `profile stop` summary, bounded `slow` and `rerenders` tables, and `timeline` only when commit timing matters; then drill into a specific `@c` ref with `profile report` instead of repeatedly raising broad `profile slow` limits.
3536

3637
React Native warning/error overlays belong to the app run. Treat them as findings or blockers: capture them, check `react-devtools errors` when connected, dismiss visible `Dismiss`/`Close` controls only when unrelated, then re-snapshot and report the overlay.
3738

0 commit comments

Comments
 (0)