use Unix Nano timestamp for "now" in poolCommon#378
Merged
panjf2000 merged 1 commit intopanjf2000:devfrom Feb 4, 2026
Merged
Conversation
panjf2000
reviewed
Feb 3, 2026
The pool’s ticktock goroutine was storing time.Now() in an atomic.Value, which incurs interface boxing and shows up as runtime.convT in profiles. Switch to storing Unix nanos in an int64 with atomic.Load/StoreInt64, and reconstruct time.Time in nowTime(). This preserves behavior while removing the per‑tick allocation and conversion overhead, especially when many pools are created. change name
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #378 +/- ##
=======================================
Coverage 94.03% 94.03%
=======================================
Files 14 14
Lines 788 788
=======================================
Hits 741 741
Misses 35 35
Partials 12 12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The pool’s ticktock goroutine was storing time.Now() in an atomic.Value, which incurs interface boxing and shows up as runtime.convT in profiles. Switch to storing Unix nanos in an int64 with atomic.Load/StoreInt64, and reconstruct time.Time in nowTime(). This preserves behavior while removing the per‑tick allocation and conversion overhead, especially when many pools are created.
1. Are you opening this pull request for bug-fixs, optimizations or new feature?
This is an optimization.
2. Please describe how these code changes achieve your intention.
Each ants pool runs a ticktock() goroutine that periodically caches time.Now() in an atomic.Value. With many pools, the repeated interface boxing and atomic.Value store shows up as runtime.convT in CPU profiles and adds measurable overhead. By switching the cached value to a plain int64 holding Unix nanoseconds and using atomic.StoreInt64/LoadInt64, we keep the same cached‑time behavior for worker expiry but remove the conversion and allocation cost. This reduces per‑pool CPU overhead while preserving existing semantics for idle worker expiration.
3. Please link to the relevant issues (if any).
4. Which documentation changes (if any) need to be made/updated because of this PR?
4. Checklist