test: stabilize codspeed CPU benchmarks - #7987
Conversation
|
View your CI Pipeline Execution ↗ for commit fe294d7
☁️ Nx Cloud last updated this comment at |
🚀 Changeset Version PreviewNo changeset entries found. Merging this PR will not cause a version bump for any packages. |
📝 WalkthroughWalkthroughThe PR updates client-navigation benchmarks to use harness-managed history and per-invocation lifecycle handling. It also changes SSR benchmarks to deterministic concurrent request loops with explicit workload counts, validation tests, Vitest configuration, and TypeScript checking. ChangesClient-navigation benchmark history
SSR benchmark concurrency
Estimated code review effort: 5 (Critical) | ~120 minutes Sequence Diagram(s)sequenceDiagram
participant Benchmark
participant ClientNavHarness
participant Router
participant History
Benchmark->>ClientNavHarness: create scenario state
ClientNavHarness->>History: create browser or memory history
ClientNavHarness->>Router: mount with RouterHistory
Benchmark->>Router: execute navigation ticks
Benchmark->>ClientNavHarness: finishBatch
ClientNavHarness->>History: dispose history and restore resources
sequenceDiagram
participant SSRBenchmark
participant runRequestLoop
participant RequestWorkers
participant SSRServer
SSRBenchmark->>runRequestLoop: provide concurrency and totalRequests
runRequestLoop->>RequestWorkers: build and distribute request sequences
RequestWorkers->>SSRServer: execute requests concurrently
SSRServer-->>RequestWorkers: return response bodies
RequestWorkers->>runRequestLoop: drain and validate responses
runRequestLoop-->>SSRBenchmark: resolve or reject after workers settle
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Bundle Size BenchmarksThis pull request does not affect bundle size in any measured scenario. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@benchmarks/client-nav/package.json`:
- Line 22: Update the `@tanstack/history` dependency declaration in package.json
to use the workspace:* protocol instead of workspace:^, preserving it as an
internal workspace dependency.
In `@benchmarks/client-nav/scenarios/harness.ts`:
- Around line 161-166: Update the teardown function returned by
restoreTimeouts() to cancel every tracked setImmediate callback and clear the
tracking collection before restoring targetWindow.setTimeout and
targetWindow.clearTimeout. Ensure pending callbacks cannot run after teardown,
while preserving the existing timer-method restoration.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 78324e95-3e8b-4367-8d62-274084374bfb
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (98)
benchmarks/client-nav/package.jsonbenchmarks/client-nav/scenarios/async-pipeline/react/speed.bench.tsbenchmarks/client-nav/scenarios/async-pipeline/react/src/main.tsxbenchmarks/client-nav/scenarios/async-pipeline/solid/speed.bench.tsbenchmarks/client-nav/scenarios/async-pipeline/solid/src/main.tsxbenchmarks/client-nav/scenarios/async-pipeline/vue/speed.bench.tsbenchmarks/client-nav/scenarios/async-pipeline/vue/src/main.tsxbenchmarks/client-nav/scenarios/control-flow/react/speed.bench.tsbenchmarks/client-nav/scenarios/control-flow/react/src/main.tsxbenchmarks/client-nav/scenarios/control-flow/solid/speed.bench.tsbenchmarks/client-nav/scenarios/control-flow/solid/src/main.tsxbenchmarks/client-nav/scenarios/control-flow/vue/speed.bench.tsbenchmarks/client-nav/scenarios/control-flow/vue/src/main.tsxbenchmarks/client-nav/scenarios/harness.tsbenchmarks/client-nav/scenarios/head/react/speed.bench.tsbenchmarks/client-nav/scenarios/head/react/src/main.tsxbenchmarks/client-nav/scenarios/head/solid/speed.bench.tsbenchmarks/client-nav/scenarios/head/solid/src/main.tsxbenchmarks/client-nav/scenarios/head/vue/speed.bench.tsbenchmarks/client-nav/scenarios/head/vue/src/main.tsxbenchmarks/client-nav/scenarios/history/react/setup.tsbenchmarks/client-nav/scenarios/history/react/speed.bench.tsbenchmarks/client-nav/scenarios/history/react/src/main.tsxbenchmarks/client-nav/scenarios/history/shared.tsbenchmarks/client-nav/scenarios/history/solid/setup.tsbenchmarks/client-nav/scenarios/history/solid/speed.bench.tsbenchmarks/client-nav/scenarios/history/solid/src/main.tsxbenchmarks/client-nav/scenarios/history/vue/setup.tsbenchmarks/client-nav/scenarios/history/vue/speed.bench.tsbenchmarks/client-nav/scenarios/history/vue/src/main.tsxbenchmarks/client-nav/scenarios/links/react/speed.bench.tsbenchmarks/client-nav/scenarios/links/react/src/main.tsxbenchmarks/client-nav/scenarios/links/solid/speed.bench.tsbenchmarks/client-nav/scenarios/links/solid/src/main.tsxbenchmarks/client-nav/scenarios/links/vue/speed.bench.tsbenchmarks/client-nav/scenarios/links/vue/src/main.tsxbenchmarks/client-nav/scenarios/loaders/react/speed.bench.tsbenchmarks/client-nav/scenarios/loaders/react/src/main.tsxbenchmarks/client-nav/scenarios/loaders/solid/speed.bench.tsbenchmarks/client-nav/scenarios/loaders/solid/src/main.tsxbenchmarks/client-nav/scenarios/loaders/vue/speed.bench.tsbenchmarks/client-nav/scenarios/loaders/vue/src/main.tsxbenchmarks/client-nav/scenarios/mount/react/speed.bench.tsbenchmarks/client-nav/scenarios/mount/react/src/main.tsxbenchmarks/client-nav/scenarios/mount/solid/speed.bench.tsbenchmarks/client-nav/scenarios/mount/solid/src/main.tsxbenchmarks/client-nav/scenarios/mount/vue/speed.bench.tsbenchmarks/client-nav/scenarios/mount/vue/src/main.tsxbenchmarks/client-nav/scenarios/nested-params/react/speed.bench.tsbenchmarks/client-nav/scenarios/nested-params/react/src/main.tsxbenchmarks/client-nav/scenarios/nested-params/solid/speed.bench.tsbenchmarks/client-nav/scenarios/nested-params/solid/src/main.tsxbenchmarks/client-nav/scenarios/nested-params/vue/speed.bench.tsbenchmarks/client-nav/scenarios/nested-params/vue/src/main.tsxbenchmarks/client-nav/scenarios/preload/react/speed.bench.tsbenchmarks/client-nav/scenarios/preload/react/src/main.tsxbenchmarks/client-nav/scenarios/preload/solid/speed.bench.tsbenchmarks/client-nav/scenarios/preload/solid/src/main.tsxbenchmarks/client-nav/scenarios/preload/vue/speed.bench.tsbenchmarks/client-nav/scenarios/preload/vue/src/main.tsxbenchmarks/client-nav/scenarios/rewrites/react/speed.bench.tsbenchmarks/client-nav/scenarios/rewrites/react/src/main.tsxbenchmarks/client-nav/scenarios/rewrites/shared.tsbenchmarks/client-nav/scenarios/rewrites/solid/speed.bench.tsbenchmarks/client-nav/scenarios/rewrites/solid/src/main.tsxbenchmarks/client-nav/scenarios/rewrites/vue/speed.bench.tsbenchmarks/client-nav/scenarios/rewrites/vue/src/main.tsxbenchmarks/client-nav/scenarios/route-tree-scale/react/speed.bench.tsbenchmarks/client-nav/scenarios/route-tree-scale/react/src/main.tsxbenchmarks/client-nav/scenarios/route-tree-scale/solid/speed.bench.tsbenchmarks/client-nav/scenarios/route-tree-scale/solid/src/main.tsxbenchmarks/client-nav/scenarios/route-tree-scale/vue/speed.bench.tsbenchmarks/client-nav/scenarios/route-tree-scale/vue/src/main.tsxbenchmarks/client-nav/scenarios/search-params/react/speed.bench.tsbenchmarks/client-nav/scenarios/search-params/react/src/main.tsxbenchmarks/client-nav/scenarios/search-params/solid/speed.bench.tsbenchmarks/client-nav/scenarios/search-params/solid/src/main.tsxbenchmarks/client-nav/scenarios/search-params/vue/speed.bench.tsbenchmarks/client-nav/scenarios/search-params/vue/src/main.tsxbenchmarks/ssr/bench-utils.test.tsbenchmarks/ssr/bench-utils.tsbenchmarks/ssr/package.jsonbenchmarks/ssr/scenarios/assets/shared.tsbenchmarks/ssr/scenarios/before-load/shared-bench.tsbenchmarks/ssr/scenarios/control-flow/shared.tsbenchmarks/ssr/scenarios/global-middleware/bench.tsbenchmarks/ssr/scenarios/head/shared.tsbenchmarks/ssr/scenarios/loaders/shared-bench.tsbenchmarks/ssr/scenarios/rewrites/shared.tsbenchmarks/ssr/scenarios/selective-ssr/shared-bench.tsbenchmarks/ssr/scenarios/serialization/shared-bench.tsbenchmarks/ssr/scenarios/server-fn-transport/bench.tsbenchmarks/ssr/scenarios/server-fns/bench.tsbenchmarks/ssr/scenarios/server-routes-middleware/shared.tsbenchmarks/ssr/scenarios/server-routes/shared.tsbenchmarks/ssr/scenarios/streaming/shared-bench.tsbenchmarks/ssr/tsconfig.jsonbenchmarks/ssr/vitest.unit.config.ts
| "test:types:vue": "tsc -p ./vue/tsconfig.json --noEmit" | ||
| }, | ||
| "dependencies": { | ||
| "@tanstack/history": "workspace:^", |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Use the required workspace protocol.
Replace workspace:^ with workspace:* for this internal dependency.
As per coding guidelines, "**/package.json: Use workspace protocol (workspace:*) for internal dependencies."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@benchmarks/client-nav/package.json` at line 22, Update the `@tanstack/history`
dependency declaration in package.json to use the workspace:* protocol instead
of workspace:^, preserving it as an internal workspace dependency.
Source: Coding guidelines
| return () => { | ||
| window.setTimeout = originalSetTimeout as typeof window.setTimeout | ||
| window.clearTimeout = originalClearTimeout as typeof window.clearTimeout | ||
| targetWindow.setTimeout = | ||
| originalSetTimeout as typeof targetWindow.setTimeout | ||
| targetWindow.clearTimeout = | ||
| originalClearTimeout as typeof targetWindow.clearTimeout | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Cancel pending patched timers during teardown.
restoreTimeouts() restores the timer methods but leaves queued setImmediate callbacks active. A callback queued before after() can run after unmount, history destruction, or JSDOM window closure. Cancel and clear all tracked immediates before restoring the methods.
Proposed fix
return () => {
+ for (const immediate of immediates.values()) {
+ clearImmediate(immediate)
+ }
+ immediates.clear()
targetWindow.setTimeout =
originalSetTimeout as typeof targetWindow.setTimeout
targetWindow.clearTimeout =
originalClearTimeout as typeof targetWindow.clearTimeout
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| return () => { | |
| window.setTimeout = originalSetTimeout as typeof window.setTimeout | |
| window.clearTimeout = originalClearTimeout as typeof window.clearTimeout | |
| targetWindow.setTimeout = | |
| originalSetTimeout as typeof targetWindow.setTimeout | |
| targetWindow.clearTimeout = | |
| originalClearTimeout as typeof targetWindow.clearTimeout | |
| } | |
| return () => { | |
| for (const immediate of immediates.values()) { | |
| clearImmediate(immediate) | |
| } | |
| immediates.clear() | |
| targetWindow.setTimeout = | |
| originalSetTimeout as typeof targetWindow.setTimeout | |
| targetWindow.clearTimeout = | |
| originalClearTimeout as typeof targetWindow.clearTimeout | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@benchmarks/client-nav/scenarios/harness.ts` around lines 161 - 166, Update
the teardown function returned by restoreTimeouts() to cancel every tracked
setImmediate callback and clear the tracking collection before restoring
targetWindow.setTimeout and targetWindow.clearTimeout. Ensure pending callbacks
cannot run after teardown, while preserving the existing timer-method
restoration.
Merging this PR will degrade performance by 12.86%
|
Summary by CodeRabbit