Memoization / caching of cipher computations#102
Conversation
|
@Aditya8369 is attempting to deploy a commit to the csxark's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Review limit reached
Next review available in: 47 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
csxark
left a comment
There was a problem hiding this comment.
Great work @Aditya8369, and thank you for your contribution! 🎉I've reviewed the changes, and everything looks good. The requested fixes have been addressed correctly, and the implementation aligns well with the requirements. This is ready to be merged. Looking forward to your future contributions!
Summary of Changes
lib/hooks/useCipherWorker.ts:
Persistent cache: Introduced a module-level resultCache Map which retains results across component cycles, unmounts, and worker thread recreations.
LRU cache eviction policy: Enforced a MAX_CACHE_SIZE = 200 limit. When reached, it automatically evicts the oldest items to avoid memory leaks.
Stable sorting keys: Added sortObjectKeys helper to recursively sort keys of options, ensuring that identical parameters are matched correctly regardless of property definition ordering.
Cache bypassing: Supports a bypassCache?: boolean option inside options to force computations to run on the Web Worker thread (essential for testing or raw benchmarks).
Cache reset: Exposed a clearCipherWorkerCache() utility for isolated test setup.
tests/unit/hooks/useCipherWorker.test.ts:
Added unit tests for memoization (ensuring repeated worker execution is bypassed), the bypassCache option, and the LRU boundary constraint/eviction mechanism. All tests compile and pass successfully.
closes #83