Skip to content

bench(memory): add settle macro/micro-tasks after each loop to reduce peak memory allocation (hopefully)#7632

Open
Sheraff wants to merge 1 commit into
mainfrom
bench-memory-rest-to-reduce-peaks-maybe
Open

bench(memory): add settle macro/micro-tasks after each loop to reduce peak memory allocation (hopefully)#7632
Sheraff wants to merge 1 commit into
mainfrom
bench-memory-rest-to-reduce-peaks-maybe

Conversation

@Sheraff

@Sheraff Sheraff commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Tests

    • Enhanced benchmark test suites with improved render and response settling mechanisms to ensure more accurate performance measurements during iterative test cycles.
  • Chores

    • Refined internal test infrastructure to better synchronize framework lifecycle events and event loop processing across client and server benchmark scenarios.

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c891b7d4-5786-4a58-be93-70eb41c65868

📥 Commits

Reviewing files that changed from the base of the PR and between a415471 and eef37f2.

📒 Files selected for processing (9)
  • benchmarks/memory/client/lifecycle.ts
  • benchmarks/memory/client/scenarios/interrupted-navigations/shared.ts
  • benchmarks/memory/client/scenarios/loader-data-retention/shared.ts
  • benchmarks/memory/client/scenarios/mount-unmount/shared.ts
  • benchmarks/memory/client/scenarios/navigation-churn/shared.ts
  • benchmarks/memory/client/scenarios/preload-churn/shared.ts
  • benchmarks/memory/client/scenarios/unique-location-churn/shared.ts
  • benchmarks/memory/server/bench-utils.ts
  • benchmarks/memory/server/scenarios/aborted-requests/shared.ts

📝 Walkthrough

Walkthrough

Two new async settling helpers are introduced for memory benchmarks: settleAfterRender() (client-side, flushes microtasks then one animation frame) and settleAfterDrainResponse() (server-side, flushes microtasks then a setImmediate). Both are then applied across all relevant client scenario files and the server aborted-requests scenario to prevent post-iteration cleanup work from leaking into the next measurement sample.

Changes

Benchmark Settle Helpers

Layer / File(s) Summary
Client settleAfterRender helper
benchmarks/memory/client/lifecycle.ts
Exports settleAfterRender(), which chains drainMicrotasks() and nextAnimationFrame() to wait for render and signal effects to settle.
Apply settleAfterRender across client scenarios
benchmarks/memory/client/scenarios/interrupted-navigations/shared.ts, benchmarks/memory/client/scenarios/loader-data-retention/shared.ts, benchmarks/memory/client/scenarios/mount-unmount/shared.ts, benchmarks/memory/client/scenarios/navigation-churn/shared.ts, benchmarks/memory/client/scenarios/preload-churn/shared.ts, benchmarks/memory/client/scenarios/unique-location-churn/shared.ts
All six client scenario files add settleAfterRender to their lifecycle imports and call it after successful render assertions, after retry loops, and in setup paths after router.load().
Server settleAfterDrainResponse helper and scenario usage
benchmarks/memory/server/bench-utils.ts, benchmarks/memory/server/scenarios/aborted-requests/shared.ts
Exports settleAfterDrainResponse() (two microtask yields + setImmediate) in bench-utils.ts, calls it in runSequentialRequestLoop after each drainResponse, and replaces two inline Promise.resolve() yields in drainCancellation with the new helper.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop, hop, settle down!
The renders swirl and spin,
I drain the microtasks away,
Then wait for frames to begin.
No leftover work shall sneak
Into my benchmark churn —
A steady queue, a steady heap,
Is all I ask in return!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.90% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the PR: adding settle mechanisms (macro/micro-tasks) to reduce peak memory allocation in benchmarks, which is directly reflected in the changes across multiple benchmark files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bench-memory-rest-to-reduce-peaks-maybe

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud

nx-cloud Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit eef37f2

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 4m 25s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 2m 12s View ↗

☁️ Nx Cloud last updated this comment at 2026-06-14 21:54:11 UTC

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

3 package(s) bumped directly, 10 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/react-router 1.170.15 → 1.170.16 Changeset
@tanstack/solid-router 1.170.15 → 1.170.16 Changeset
@tanstack/start-server-core 1.169.14 → 1.169.15 Changeset
@tanstack/react-start 1.168.25 → 1.168.26 Dependent
@tanstack/react-start-client 1.168.13 → 1.168.14 Dependent
@tanstack/react-start-rsc 0.1.24 → 0.1.25 Dependent
@tanstack/react-start-server 1.167.19 → 1.167.20 Dependent
@tanstack/solid-start 1.168.25 → 1.168.26 Dependent
@tanstack/solid-start-client 1.168.13 → 1.168.14 Dependent
@tanstack/solid-start-server 1.167.19 → 1.167.20 Dependent
@tanstack/start-plugin-core 1.171.17 → 1.171.18 Dependent
@tanstack/vue-start 1.168.24 → 1.168.25 Dependent
@tanstack/vue-start-server 1.167.19 → 1.167.20 Dependent

@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

  • Commit: dd8bc4bdf487
  • Measured at: 2026-06-14T21:50:46.241Z
  • Baseline source: history:a41547143795
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Initial gzip Raw Brotli Trend
react-router.minimal 87.33 KiB 0 B (0.00%) 87.19 KiB 273.80 KiB 76.00 KiB ▁▁▂▅▅▅▅▅▅▅█
react-router.full 91.06 KiB 0 B (0.00%) 90.92 KiB 285.70 KiB 79.10 KiB ▁▁▁▄▄▄▄▄▄▄█
solid-router.minimal 35.53 KiB 0 B (0.00%) 35.40 KiB 106.00 KiB 31.98 KiB ▃▁▁▁▁▁▁▁▁▁█
solid-router.full 40.58 KiB 0 B (0.00%) 40.46 KiB 121.22 KiB 36.50 KiB ▂▁▁▁▁▁▁▁▁▁█
vue-router.minimal 53.01 KiB 0 B (0.00%) 52.88 KiB 150.04 KiB 47.68 KiB ▁▁▁▁▁▁▁▁▁▁█
vue-router.full 58.99 KiB 0 B (0.00%) 58.86 KiB 168.80 KiB 52.88 KiB ▁▁▁▁▁▁▁▁▁▁█
react-start.minimal 101.95 KiB 0 B (0.00%) 101.82 KiB 322.12 KiB 88.14 KiB ▁▁▁▄▄▄▄▄▄▄█
react-start.deferred-hydration 102.69 KiB 0 B (0.00%) 101.84 KiB 323.50 KiB 88.98 KiB ▁▁▁▄▄▄▄▄▄▄█
react-start.full 105.36 KiB 0 B (0.00%) 105.22 KiB 332.05 KiB 91.25 KiB ▁▁▁▄▄▄▄▄▄▄█
react-start.rsbuild.minimal 99.67 KiB 0 B (0.00%) 99.50 KiB 316.56 KiB 85.76 KiB ▁▁▁▅▅▅▅▅▅▅█
react-start.rsbuild.minimal-iife 100.07 KiB 0 B (0.00%) 99.90 KiB 317.50 KiB 86.17 KiB ▁▁▁▅▅▅▅▅▅▅█
react-start.rsbuild.full 102.89 KiB 0 B (0.00%) 102.72 KiB 326.62 KiB 88.50 KiB ▁▁▁▅▅▅▅▅▅▅█
solid-start.minimal 49.64 KiB 0 B (0.00%) 49.51 KiB 152.07 KiB 43.77 KiB ▂▁▁▁▁▁▁▁▁▁█
solid-start.deferred-hydration 52.90 KiB 0 B (0.00%) 49.57 KiB 160.11 KiB 46.81 KiB ▂▁▁▁▁▁▁▁▁▁█
solid-start.full 55.45 KiB 0 B (0.00%) 55.31 KiB 169.11 KiB 48.92 KiB ▃▁▁▁▁▁▁▁▁▁█
vue-start.minimal 71.07 KiB 0 B (0.00%) 70.94 KiB 207.19 KiB 62.89 KiB ▁▁▁▁▁▁▁▁▁▁█
vue-start.full 75.06 KiB 0 B (0.00%) 74.93 KiB 219.82 KiB 66.35 KiB ▁▁▁▁▁▁▁▁▁▁█

Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better.

@pkg-pr-new

pkg-pr-new Bot commented Jun 14, 2026

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@7632

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@7632

@tanstack/eslint-plugin-start

npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@7632

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@7632

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@7632

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@7632

@tanstack/react-router-devtools

npm i https://pkg.pr.new/@tanstack/react-router-devtools@7632

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@7632

@tanstack/react-start

npm i https://pkg.pr.new/@tanstack/react-start@7632

@tanstack/react-start-client

npm i https://pkg.pr.new/@tanstack/react-start-client@7632

@tanstack/react-start-rsc

npm i https://pkg.pr.new/@tanstack/react-start-rsc@7632

@tanstack/react-start-server

npm i https://pkg.pr.new/@tanstack/react-start-server@7632

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@7632

@tanstack/router-core

npm i https://pkg.pr.new/@tanstack/router-core@7632

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@7632

@tanstack/router-devtools-core

npm i https://pkg.pr.new/@tanstack/router-devtools-core@7632

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@7632

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@7632

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@7632

@tanstack/router-utils

npm i https://pkg.pr.new/@tanstack/router-utils@7632

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@7632

@tanstack/solid-router

npm i https://pkg.pr.new/@tanstack/solid-router@7632

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/@tanstack/solid-router-devtools@7632

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@7632

@tanstack/solid-start

npm i https://pkg.pr.new/@tanstack/solid-start@7632

@tanstack/solid-start-client

npm i https://pkg.pr.new/@tanstack/solid-start-client@7632

@tanstack/solid-start-server

npm i https://pkg.pr.new/@tanstack/solid-start-server@7632

@tanstack/start-client-core

npm i https://pkg.pr.new/@tanstack/start-client-core@7632

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/@tanstack/start-fn-stubs@7632

@tanstack/start-plugin-core

npm i https://pkg.pr.new/@tanstack/start-plugin-core@7632

@tanstack/start-server-core

npm i https://pkg.pr.new/@tanstack/start-server-core@7632

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/@tanstack/start-static-server-functions@7632

@tanstack/start-storage-context

npm i https://pkg.pr.new/@tanstack/start-storage-context@7632

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@7632

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@7632

@tanstack/vue-router

npm i https://pkg.pr.new/@tanstack/vue-router@7632

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/@tanstack/vue-router-devtools@7632

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@7632

@tanstack/vue-start

npm i https://pkg.pr.new/@tanstack/vue-start@7632

@tanstack/vue-start-client

npm i https://pkg.pr.new/@tanstack/vue-start-client@7632

@tanstack/vue-start-server

npm i https://pkg.pr.new/@tanstack/vue-start-server@7632

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@7632

commit: eef37f2

@codspeed-hq

codspeed-hq Bot commented Jun 14, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 3.11%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 10 improved benchmarks
❌ 13 regressed benchmarks
✅ 121 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory mem mount-unmount (solid) 492.9 KB 1,146.1 KB -57%
Memory mem aborted-requests (react) 1.1 MB 2.2 MB -50.61%
Memory mem unique-location-churn (solid) 842.4 KB 1,435.8 KB -41.33%
Memory mem interrupted-navigations (solid) 845.1 KB 1,437.4 KB -41.21%
Memory mem peak-large-page (react) 2 MB 3.1 MB -35.23%
Memory mem loader-data-retention (solid) 158.5 KB 229.5 KB -30.94%
Memory mem error-paths redirect (react) 469.9 KB 667.9 KB -29.65%
Memory mem peak-large-page (vue) 2.2 MB 2.9 MB -23.2%
Memory mem preload-churn (solid) 580.3 KB 704.7 KB -17.65%
Memory mem request-churn (solid) 1.1 MB 1.3 MB -15.18%
Memory mem loader-data-retention (react) 203.4 KB 223 KB -8.79%
Simulation ssr dehydrate plain control (vue) 145 ms 151.3 ms -4.15%
Memory mem aborted-requests (vue) 982.4 KB 1,014.4 KB -3.15%
Memory mem serialization-payload (react) 35 MB 6.4 MB ×5.5
Memory mem error-paths unmatched (react) 1,120.8 KB 517.9 KB ×2.2
Memory mem navigation-churn (vue) 992.1 KB 553.3 KB +79.3%
Memory mem aborted-requests (solid) 2.7 MB 2.3 MB +21.05%
Memory mem error-paths error (react) 815.4 KB 678.4 KB +20.2%
Memory mem unique-location-churn (vue) 1,156.7 KB 1,005.4 KB +15.05%
Memory mem error-paths not-found (react) 941.6 KB 851.3 KB +10.61%
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing bench-memory-rest-to-reduce-peaks-maybe (eef37f2) with main (a415471)

Open in CodSpeed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant