Skip to content

fix: update getOptimalThreadCount to work in browsers#1137

Merged
cedoor merged 4 commits into
mainfrom
fix/build-client
Dec 22, 2025
Merged

fix: update getOptimalThreadCount to work in browsers#1137
cedoor merged 4 commits into
mainfrom
fix/build-client

Conversation

@cedoor

@cedoor cedoor commented Dec 22, 2025

Copy link
Copy Markdown
Contributor

Fixes #1136

Summary by CodeRabbit

  • Performance

    • Improved thread-count selection to prioritize browser detection, use available CPU capacity, enforce a sensible minimum, and keep a stable default fallback when info is unavailable.
  • Improvements

    • More robust runtime detection across browser and server environments with added error handling to avoid failures.
  • Chores

    • Package versions bumped from 0.5.4 to 0.5.6 across example packages.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel

vercel Bot commented Dec 22, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Review Updated (UTC)
crisp Skipped Skipped Dec 22, 2025 0:06am
enclave-docs Skipped Skipped Dec 22, 2025 0:06am

@cedoor cedoor requested a review from ctrlc03 December 22, 2025 11:24
@coderabbitai

coderabbitai Bot commented Dec 22, 2025

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@cedoor has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 32 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between e806e2f and c6513e4.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • examples/CRISP/client/package.json
  • examples/CRISP/packages/crisp-contracts/package.json
  • examples/CRISP/packages/crisp-sdk/package.json
  • examples/CRISP/packages/crisp-sdk/src/utils.ts
  • examples/CRISP/packages/crisp-zk-inputs/package.json

Walkthrough

getOptimalThreadCount now prefers browser detection via navigator.hardwareConcurrency, uses a guarded dynamic import('os') in Node.js to read availableParallelism() or os.cpus().length, wraps Node path in try/catch, and falls back to a default of 5. Package versions bumped from 0.5.4 → 0.5.6.

Changes

Cohort / File(s) Summary
Thread count detection and fallback
examples/CRISP/packages/crisp-sdk/src/utils.ts
Moves browser check to the top (uses navigator.hardwareConcurrency - 1, min 1). Replaces direct process usage with guarded detection via window/globalThis/globalThis.process. Dynamically imports os under the Node guard; uses os.availableParallelism() if available, else os.cpus().length, subtracts one and ensures ≥1. Wraps Node logic in try/catch and keeps final fallback of 5. Docstring wording adjusted; exported signature unchanged.
Package version bumps
examples/CRISP/client/package.json, examples/CRISP/packages/crisp-contracts/package.json, examples/CRISP/packages/crisp-sdk/package.json, examples/CRISP/packages/crisp-zk-inputs/package.json
Bumped package versions from 0.5.4 to 0.5.6 across CRISP example packages. No other manifest or dependency changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify the dynamic import('os') won't cause bundler resolution issues (e.g., Vite) or reintroduce the previous build error.
  • Confirm the guarded Node detection logic is correct for all target runtimes and build environments.
  • Check fallback behavior and any tests covering failure paths.

Possibly related PRs

  • chore: v0.0.2-test #979 — Also updates CRISP example package versions; related because this PR similarly bumps versions and touches crisp-sdk (though #979 did not modify utils.ts).

Suggested reviewers

  • ctrlc03

Poem

🐇 I nibble cores beneath the silver sky,
I peek at browsers first — then quietly try.
If Node awakes, I call os with care,
Fallbacks snug like carrots in my lair. 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (5 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 change—refactoring getOptimalThreadCount to support browser environments by removing direct Node.js dependencies.
Linked Issues check ✅ Passed The code changes successfully address #1136 by eliminating the direct process module import and replacing it with environment detection and dynamic imports, resolving the Vite build failure.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the build issue; version bumps in package.json files are standard release practices accompanying the functional fix.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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.

ctrlc03
ctrlc03 previously approved these changes Dec 22, 2025

@ctrlc03 ctrlc03 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

utACK

@vercel vercel Bot temporarily deployed to Preview – crisp December 22, 2025 11:31 Inactive
@vercel vercel Bot temporarily deployed to Preview – enclave-docs December 22, 2025 11:31 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp December 22, 2025 11:37 Inactive
ctrlc03
ctrlc03 previously approved these changes Dec 22, 2025
@vercel vercel Bot temporarily deployed to Preview – enclave-docs December 22, 2025 11:37 Inactive

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
examples/CRISP/packages/crisp-sdk/src/utils.ts (1)

146-152: Fallback handling is appropriate.

The try/catch ensures graceful degradation when the dynamic import fails (e.g., in browsers or restricted environments). The fallback value of 5 threads is reasonable, though you might consider documenting this default in the function's docstring for clarity.

Optional: Document the fallback value in the docstring
 /**
  * Get optimal number of threads for proof generation.
  * Leaves at least 1 core free for other operations.
  * Works in both Node.js and browser environments.
+ * Falls back to 5 threads if hardware concurrency cannot be determined.
  */
📜 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 9e7ecde and faccec5.

📒 Files selected for processing (1)
  • examples/CRISP/packages/crisp-sdk/src/utils.ts
⏰ 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). (9)
  • GitHub Check: build_sdk
  • GitHub Check: build_e3_support_dev
  • GitHub Check: build_enclave_cli
  • GitHub Check: build_crisp_sdk
  • GitHub Check: test_net
  • GitHub Check: integration_prebuild
  • GitHub Check: rust_unit
  • GitHub Check: rust_integration
  • GitHub Check: build_ciphernode_image
🔇 Additional comments (4)
examples/CRISP/packages/crisp-sdk/src/utils.ts (4)

127-130: Documentation improvements look good.

The updated docstring accurately reflects the cross-environment nature of the function and is clearer with "1 core" instead of "one core."


132-135: Excellent browser-first approach.

Checking for navigator.hardwareConcurrency before attempting any Node.js-specific imports is the correct solution for preventing bundler issues. The logic correctly reserves one core while ensuring a minimum of 1 thread.


140-145: Dynamic import and CPU detection logic is solid.

Using await import('os') prevents the module from being statically bundled for browsers. The fallback from availableParallelism() to cpus().length handles different Node.js versions gracefully.


137-139: The Node.js detection correctly uses typeof globalThis.process !== 'undefined' to avoid triggering polyfill resolution.

The implementation properly avoids directly referencing process as an identifier. By accessing it as a property of globalThis within a typeof check, the code prevents bundlers from scanning for top-level process imports that would trigger the polyfill plugin. The three-part condition correctly identifies Node.js environments (not browser, globalThis available, process present) without causing build failures.

- Updated @crisp-e3/sdk to 0.5.6
- Updated @crisp-e3/contracts to 0.5.6
- Updated @crisp-e3/zk-inputs to 0.5.6
- Published to npm
@cedoor cedoor enabled auto-merge (squash) December 22, 2025 12:06
@vercel vercel Bot temporarily deployed to Preview – enclave-docs December 22, 2025 12:06 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp December 22, 2025 12:06 Inactive
@cedoor cedoor merged commit 007d0c2 into main Dec 22, 2025
25 checks passed
@ctrlc03 ctrlc03 deleted the fix/build-client branch December 22, 2025 12:34
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.

CRISP frontend does not build

2 participants