Skip to content

perf(react-runtime): trim snapshot and commit hot paths#2353

Merged
Yradex merged 2 commits intolynx-family:mainfrom
colinaaa:codex/runtime-micro-trims
Mar 30, 2026
Merged

perf(react-runtime): trim snapshot and commit hot paths#2353
Yradex merged 2 commits intolynx-family:mainfrom
colinaaa:codex/runtime-micro-trims

Conversation

@colinaaa
Copy link
Copy Markdown
Collaborator

@colinaaa colinaaa commented Mar 18, 2026

This extracts the misc micro-trims from bundle-size into a standalone slice.

  • simplify BackgroundSnapshotInstance.childNodes() by iterating directly until null
  • drop redundant guards in commit patch assembly now that snapshotPatch is guaranteed after the early return

Validation: git diff --check

pnpm exec biome check could not run in this worktree because biome is not installed locally.

issue: #17

Summary by CodeRabbit

  • Refactor
    • Optimized internal conditional logic for improved code efficiency.
    • Enhanced child node traversal handling for better performance.

- remove the redundant childNodes break guard in BackgroundSnapshotInstance
- simplify commit patch guards now that snapshotPatch is always defined after the early return

Validation: git diff --check
@colinaaa colinaaa requested review from HuJean, Yradex and hzy as code owners March 18, 2026 14:12
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 18, 2026

📝 Walkthrough

Walkthrough

Two files in the snapshot and lifecycle modules are refined. The patch commit logic removes redundant null-chaining guards leveraging existing control flow. The background snapshot child node traversal is modified to eliminate early loop termination, iterating solely via sibling linkage.

Changes

Cohort / File(s) Summary
Snapshot Lifecycle Cleanup
packages/react/runtime/src/lifecycle/patch/commit.ts
Simplified conditional guards by removing optional-chaining syntax (?.) in two places: snapshotPatch?.length becomes snapshotPatch.length, and snapshotPatch && delayedRunOnMainThreadData.length becomes delayedRunOnMainThreadData.length, relying on existing early-return control flow.
Node Traversal Logic
packages/react/runtime/src/snapshot/backgroundSnapshot.ts
Removed early-termination condition in BackgroundSnapshotInstance.childNodes loop; node iteration now continues via sibling chain until completion rather than stopping at recorded __lastChild.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • HuJean
  • Yradex
  • hzy

Poem

🐰 With guards now cleaner and loops set free,
The snapshot hops through sibling spree,
No early stops to break the chain,
Just simple truths—no null refrain,
Efficiency bounds through the tree!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'perf(react-runtime): trim snapshot and commit hot paths' directly summarizes the main changes: performance optimizations in snapshot and commit code paths by removing redundant guards and simplifying traversal logic.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 18, 2026

Merging this PR will degrade performance by 21.09%

❌ 1 regressed benchmark
✅ 71 untouched benchmarks
⏩ 21 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
002-hello-reactLynx-destroyBackground 679.4 µs 861 µs -21.09%

Comparing colinaaa:codex/runtime-micro-trims (28a3855) with main (95fff27)2

Open in CodSpeed

Footnotes

  1. 21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (9193711) during the generation of this report, so 95fff27 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Mar 18, 2026

Web Explorer

#8506 Bundle Size — 728.6KiB (0%).

28a3855(current) vs 7b7a0c6 main#8505(baseline)

Bundle metrics  Change 1 change
                 Current
#8506
     Baseline
#8505
No change  Initial JS 43.3KiB 43.3KiB
No change  Initial CSS 2.16KiB 2.16KiB
No change  Cache Invalidation 0% 0%
No change  Chunks 8 8
No change  Assets 10 10
Change  Modules 148(-0.67%) 149
No change  Duplicate Modules 11 11
No change  Duplicate Code 34.69% 34.69%
No change  Packages 3 3
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#8506
     Baseline
#8505
No change  Other 384.4KiB 384.4KiB
No change  JS 342.04KiB 342.04KiB
No change  CSS 2.16KiB 2.16KiB

Bundle analysis reportBranch colinaaa:codex/runtime-micro-tri...Project dashboard


Generated by RelativeCIDocumentationReport issue

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 28, 2026

⚠️ No Changeset found

Latest commit: 28a3855

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Mar 28, 2026

React Example

#6928 Bundle Size — 237.85KiB (-0.02%).

28a3855(current) vs 7b7a0c6 main#6927(baseline)

Bundle metrics  Change 1 change
                 Current
#6928
     Baseline
#6927
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
Change  Cache Invalidation 38.73% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 180 180
No change  Duplicate Modules 71 71
No change  Duplicate Code 46.4% 46.4%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Improvement 1 improvement
                 Current
#6928
     Baseline
#6927
No change  IMG 145.76KiB 145.76KiB
Improvement  Other 92.09KiB (-0.05%) 92.13KiB

Bundle analysis reportBranch colinaaa:codex/runtime-micro-tri...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Mar 28, 2026

React MTF Example

#62 Bundle Size — 207.43KiB (-0.02%).

28a3855(current) vs 7b7a0c6 main#61(baseline)

Bundle metrics  Change 1 change
                 Current
#62
     Baseline
#61
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
Change  Cache Invalidation 46.39% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 174 174
No change  Duplicate Modules 68 68
No change  Duplicate Code 46.09% 46.09%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Improvement 1 improvement
                 Current
#62
     Baseline
#61
No change  IMG 111.23KiB 111.23KiB
Improvement  Other 96.19KiB (-0.04%) 96.24KiB

Bundle analysis reportBranch colinaaa:codex/runtime-micro-tri...Project dashboard


Generated by RelativeCIDocumentationReport issue

Copy link
Copy Markdown
Collaborator

@Yradex Yradex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看过了。这个 PR 基本是删冗余 guard:childNodes() 直接靠 linked-list 终止条件退出,commit.ts 里 snapshotPatch 在前置 return 之后也确实恒存在,改动和声明一致。CI 也全绿。

@Yradex Yradex merged commit a853b7a into lynx-family:main Mar 30, 2026
74 of 79 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants