fix: update getOptimalThreadCount to work in browsers#1137
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
|
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 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. ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
WalkthroughgetOptimalThreadCount now prefers browser detection via navigator.hardwareConcurrency, uses a guarded dynamic Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
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 |
9e7ecde to
faccec5
Compare
There was a problem hiding this comment.
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
📒 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.hardwareConcurrencybefore 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 fromavailableParallelism()tocpus().lengthhandles different Node.js versions gracefully.
137-139: The Node.js detection correctly usestypeof globalThis.process !== 'undefined'to avoid triggering polyfill resolution.The implementation properly avoids directly referencing
processas an identifier. By accessing it as a property ofglobalThiswithin atypeofcheck, the code prevents bundlers from scanning for top-levelprocessimports 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
e806e2f to
c6513e4
Compare
Fixes #1136
Summary by CodeRabbit
Performance
Improvements
Chores
✏️ Tip: You can customize this high-level summary in your review settings.