Skip to content

ci(benchmark/react): check Codspeed before use it#1720

Merged
hzy merged 1 commit intolynx-family:mainfrom
hzy:p/hzy/bench_12
Sep 11, 2025
Merged

ci(benchmark/react): check Codspeed before use it#1720
hzy merged 1 commit intolynx-family:mainfrom
hzy:p/hzy/bench_12

Conversation

@hzy
Copy link
Copy Markdown
Collaborator

@hzy hzy commented Sep 11, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Prevents runtime errors when an optional benchmarking tool is absent by conditionally running its instrumentation.
    • Ensures script-load and footer instrumentation execute only if the tool is available, while preserving normal behavior (including flush) when it is present.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).
  • Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Sep 11, 2025

⚠️ No Changeset found

Latest commit: d59579b

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 11, 2025

📝 Walkthrough

Walkthrough

Adds runtime guards around Codspeed instrumentation in benchmark/react/plugins/pluginScriptLoad.mjs. startBenchmark, stopBenchmark, and setExecutedBenchmark now execute only if Codspeed is defined. runAfterLoadScript.flush() remains unguarded.

Changes

Cohort / File(s) Summary
Codspeed guards in React benchmark plugin
benchmark/react/plugins/pluginScriptLoad.mjs
Wrapped Codspeed.startBenchmark(), Codspeed.stopBenchmark(), and Codspeed.setExecutedBenchmark() in if (typeof Codspeed !== "undefined") { ... }. Left runAfterLoadScript.flush() unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • upupming
  • colinaaa

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the main change: adding a guard that checks for Codspeed before it's used in the benchmark/react area. It is concise, focused on the primary behavior change, and avoids unnecessary detail. The only minor issues are a small grammatical awkwardness ("before use it" → "before using it") and that the "ci" prefix could be debated since the change modifies benchmark plugin code rather than CI configuration.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

I nibbled through scripts with delicate care,
Wrapped Codspeed calls—only run if they're there.
Benchmarks hop-start and hop-stop on cue,
Flush still sprints — the run stays true.
Thump-thump, safe footer, no ReferenceError to rue. 🐇✨

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
benchmark/react/plugins/pluginScriptLoad.mjs (2)

27-29: Harden the guard to avoid TypeErrors when Codspeed is present but APIs are missing.

Also verify the method exists, not just the object.

-if (typeof Codspeed !== "undefined") {
-  Codspeed.startBenchmark();
-}
+if (typeof Codspeed !== "undefined" && typeof Codspeed.startBenchmark === "function") {
+  Codspeed.startBenchmark();
+}

45-48: Simplify executed-benchmark string at build-time and guard individual APIs.

Avoid nested runtime templates and check each Codspeed API before calling.

-if (typeof Codspeed !== "undefined") {
-  Codspeed.stopBenchmark();
-  Codspeed.setExecutedBenchmark(`${caseDir}::\${${JSON.stringify(chunkName)}}_LoadScript`);
-}
+if (typeof Codspeed !== "undefined") {
+  if (typeof Codspeed.stopBenchmark === "function") Codspeed.stopBenchmark();
+  if (typeof Codspeed.setExecutedBenchmark === "function") {
+    Codspeed.setExecutedBenchmark(
+      ${JSON.stringify(`${caseDir}::${chunkName}_LoadScript`)}
+    );
+  }
+}
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d618304 and 8ba2bdf.

📒 Files selected for processing (1)
  • benchmark/react/plugins/pluginScriptLoad.mjs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build / Build (Windows)
  • GitHub Check: build / Build (Ubuntu)
  • GitHub Check: test-rust / Test (Ubuntu)

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 11, 2025

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 Sep 11, 2025

CodSpeed Performance Report

Merging #1720 will not alter performance

Comparing hzy:p/hzy/bench_12 (d59579b) with main (2800dce)

🎉 Hooray! codspeed-cpp just leveled up to 1.2.0!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

✅ 53 untouched

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Sep 11, 2025

Web Explorer

#5101 Bundle Size — 362.79KiB (0%).

d59579b(current) vs 2800dce main#5090(baseline)

Bundle metrics  no changes
                 Current
#5101
     Baseline
#5090
No change  Initial JS 145.21KiB 145.21KiB
No change  Initial CSS 31.89KiB 31.89KiB
No change  Cache Invalidation 0% 0%
No change  Chunks 8 8
No change  Assets 8 8
No change  Modules 219 219
No change  Duplicate Modules 16 16
No change  Duplicate Code 3.33% 3.33%
No change  Packages 4 4
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#5101
     Baseline
#5090
No change  JS 236.88KiB 236.88KiB
No change  Other 94.02KiB 94.02KiB
No change  CSS 31.89KiB 31.89KiB

Bundle analysis reportBranch hzy:p/hzy/bench_12Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Sep 11, 2025

React Example

#5108 Bundle Size — 238.2KiB (0%).

d59579b(current) vs 2800dce main#5097(baseline)

Bundle metrics  no changes
                 Current
#5108
     Baseline
#5097
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 163 163
No change  Duplicate Modules 67 67
No change  Duplicate Code 46.88% 46.88%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#5108
     Baseline
#5097
No change  IMG 145.76KiB 145.76KiB
No change  Other 92.45KiB 92.45KiB

Bundle analysis reportBranch hzy:p/hzy/bench_12Project dashboard


Generated by RelativeCIDocumentationReport issue

@hzy hzy requested a review from colinaaa September 11, 2025 08:59
@hzy hzy enabled auto-merge (squash) September 11, 2025 09:51
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
benchmark/react/plugins/pluginScriptLoad.mjs (2)

27-29: Guard is good; consider using globalThis + optional chaining to avoid null/shape edge cases.

Covers the ReferenceError. Small hardening: if a build sets Codspeed = null or exposes a partial API, optional chaining avoids crashes and keeps intent clear.

-if (typeof Codspeed !== "undefined") {
-  Codspeed.startBenchmark();
-}
+// Safe for ESM and handles null/partial API
+globalThis.Codspeed?.startBenchmark?.();

45-48: Simplify banner string and harden calls; avoid nested ${…} templating.

The nested interpolation works but is brittle and harder to read. Inject the fully-resolved name at build time, and use globalThis + optional chaining to tolerate partial Codspeed APIs.

-if (typeof Codspeed !== "undefined") {
-  Codspeed.stopBenchmark();
-  Codspeed.setExecutedBenchmark(`${caseDir}::${${JSON.stringify(chunkName)}}_LoadScript`);
-}
+if (globalThis.Codspeed) {
+  globalThis.Codspeed.stopBenchmark?.();
+  // Build-time string injection for clarity and safety
+  globalThis.Codspeed.setExecutedBenchmark?.(
+    ${JSON.stringify(`${caseDir}::${chunkName}_LoadScript`)}
+  );
+}

If you adopt this style here, consider mirroring it for the startBenchmark block above for consistency.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ba2bdf and d59579b.

📒 Files selected for processing (1)
  • benchmark/react/plugins/pluginScriptLoad.mjs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: build / Build (Ubuntu)
  • GitHub Check: build / Build (Windows)
  • GitHub Check: test-rust / Test (Ubuntu)
  • GitHub Check: test-rust / rustfmt

@hzy hzy merged commit a2f223d into lynx-family:main Sep 11, 2025
83 of 85 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