-
-
Notifications
You must be signed in to change notification settings - Fork 722
refactor(allocator): replace AtomicUsize with Cell<usize> in AllocationStats
#13043
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
Merged
graphite-app
merged 1 commit into
main
from
08-13-refactor_allocator_replace_atomicusize_with_cell_usize_in_allocationstats_
Aug 19, 2025
Merged
refactor(allocator): replace AtomicUsize with Cell<usize> in AllocationStats
#13043
graphite-app
merged 1 commit into
main
from
08-13-refactor_allocator_replace_atomicusize_with_cell_usize_in_allocationstats_
Aug 19, 2025
Conversation
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
This was referenced Aug 13, 2025
Member
Author
CodSpeed Instrumentation Performance ReportMerging #13043 will not alter performanceComparing Summary
|
76d7ef7 to
94907c8
Compare
9f84d46 to
1367a1b
Compare
94907c8 to
b85beb1
Compare
1367a1b to
5e6a9e7
Compare
aapoalas
reviewed
Aug 14, 2025
graphite-app bot
pushed a commit
that referenced
this pull request
Aug 14, 2025
Allocation tracker did not deal with possibility that counters could reach `usize::MAX`. In this case, addition would wrap around back to 0. This problem was pointed out by @aapoalas in #13043 (review). Introduce an `AtomicCounter` type which uses saturating addition, to prevent this happening. Reaching such a high allocation count is highly unlikely on 64-bit systems, but might just about be possible on 32-bit. Maybe this is overkill, but since `cargo allocs` is just an internal tool, performance is not the highest priority. So I figure on balance probably better to handle this edge case. It doesn't seem to hurt perf much. ``` # Before % hyperfine -i --warmup 3 'cargo allocs' Benchmark 1: cargo allocs Time (mean ± σ): 299.9 ms ± 2.4 ms [User: 132.8 ms, System: 31.0 ms] Range (min … max): 297.6 ms … 303.9 ms 10 runs # After % hyperfine -i --warmup 3 'cargo allocs' Benchmark 1: cargo allocs Time (mean ± σ): 301.3 ms ± 3.4 ms [User: 133.3 ms, System: 31.5 ms] Range (min … max): 297.8 ms … 310.0 ms 10 runs ``` Note: The same problem in arena allocation tracker is addressed in #13043.
b85beb1 to
fd22653
Compare
8843a5a to
45bfbd0
Compare
45bfbd0 to
1e22ad0
Compare
fd22653 to
32c7632
Compare
camc314
approved these changes
Aug 19, 2025
Member
Author
|
Thanks for reviewing Cam. Merging! |
Member
Author
Merge activity
|
…ocationStats` (#13043) `AllocationStats` (introduced in #12555 and #12937) previously had to contain `AtomicUsize`s because `Allocator` was `Sync`. #13033 removed the `Sync` impl for `Allocator`, so now there's no need for synchronization in `AllocationStats`, and these fields can be `Cell<usize>` instead.
32c7632 to
cc067c2
Compare
1e22ad0 to
93eaf5f
Compare
Base automatically changed from
08-13-refactor_semantic_implement_send_and_sync_for_scopingcell_
to
main
August 19, 2025 21:47
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.

AllocationStats(introduced in #12555 and #12937) previously had to containAtomicUsizes becauseAllocatorwasSync. #13033 removed theSyncimpl forAllocator, so now there's no need for synchronization inAllocationStats, and these fields can beCell<usize>instead.