-
Notifications
You must be signed in to change notification settings - Fork 7
perf(cache): reduce duration of long-running tests #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #148 +/- ##
==========================================
- Coverage 71.42% 71.28% -0.14%
==========================================
Files 200 200
Lines 18143 18143
==========================================
- Hits 12958 12933 -25
- Misses 4464 4487 +23
- Partials 721 723 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
📝 WalkthroughWalkthrough
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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.
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. 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 |
There was a problem hiding this 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 (3)
cache/cache_test.go (3)
67-69
: Avoid per-iteration allocation; reuse CleanStat (and optionally use a ticker).Allocating a new CleanStat each loop can create GC pressure in this hot path. Reuse a single instance and reset it.
Apply within the loop:
- cleaner.Cleanup(&CleanStat{}) - time.Sleep(10 * time.Microsecond) + stat = CleanStat{} // reset fields + cleaner.Cleanup(&stat) + time.Sleep(10 * time.Microsecond)Additionally, declare the reusable variable before the loop:
var stat CleanStat for !done.Load() { stat = CleanStat{} cleaner.Cleanup(&stat) time.Sleep(10 * time.Microsecond) }(Optional) Replace Sleep with a ticker to pace cleanups without a tight loop:
ticker := time.NewTicker(10 * time.Microsecond) defer ticker.Stop() for !done.Load() { <-ticker.C stat = CleanStat{} cleaner.Cleanup(&stat) }
95-96
: Use per-goroutine RNG and drop unused parameter.The global math/rand adds lock contention under high concurrency, and the get callback no longer uses i.
- Per-goroutine RNG sketch:
for g := 0; g < workers; g++ { seed := time.Now().UnixNano() + int64(g) go func(seed int64) { defer wgGet.Done() r := rand.New(rand.NewSource(seed)) for i := 0; i < records; i++ { get(c, i) // or update signature as below } }(seed) }
- If i is no longer needed, simplify signatures:
-func testStress(size, workers, records int, get func(*Cache[[]uint64], int)) { +func testStress(size, workers, records int, get func(*Cache[[]uint64])) { ... - get(c, i) + get(c)And update the call site accordingly.
120-120
: Confirm size accounting matches intent (32 vs 1×uint64).You report 32 bytes but return a slice of length 1. If this is intentional to stress accounting without extra allocations, fine. If not, align payload and size.
Example alignment:
- return []uint64{uint64(key)}, 32 + b := make([]uint64, 4) // 4 * 8B = 32B + b[0] = uint64(key) + return b, 32
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
cache/cache_test.go
(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
cache/cache_test.go (2)
cache/cleaner.go (1)
CleanStat
(20-29)cache/cache.go (1)
Cache
(60-68)
⏰ 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). (1)
- GitHub Check: test
🔇 Additional comments (1)
cache/cache_test.go (1)
90-94
: LGTM: constants and larger cache size improve stability and reduce thrash.Clearer intent and better control over test parameters.
Description
Increase cache capacity to reduce thrashing and speed up long-running tests.
Summary by CodeRabbit