refactor: centralizing shared-allocation accounting for Arc DFHeapSize impls#23349
Open
saadtajwar wants to merge 2 commits into
Open
refactor: centralizing shared-allocation accounting for Arc DFHeapSize impls#23349saadtajwar wants to merge 2 commits into
saadtajwar wants to merge 2 commits into
Conversation
Contributor
Author
|
cc @kosiew - thanks in advance for any feedback! :) |
mkleen
reviewed
Jul 7, 2026
mkleen
left a comment
Contributor
There was a problem hiding this comment.
@saadtajwar Thanks for working on this! I left a comment.
| } | ||
| } | ||
|
|
||
| fn count_allocation_once(ptr: usize, ctx: &mut DFHeapSizeCtx) -> bool { |
Contributor
There was a problem hiding this comment.
We could add this function directly to the DFHeapSizeCtx:
impl DFHeapSizeCtx {
fn count_allocation_once(mut self, ptr: usize) -> bool {
self.seen.insert(ptr)
}
}
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.
Which issue does this PR close?
Rationale for this change
DFHeapSize depends on a critical invariant: shared heap allocations must be counted once per traversal context. If Arc implementations drift, memory accounting becomes inconsistent and hard to reason about.
Consolidating the one-time-accounting logic improves:
Correctness durability (single source of truth for Arc dedup behavior)
Maintainability (less repeated logic)
Reviewability (future changes touch one helper)
What changes are included in this PR?
Helper functions for
Arcallocation identity and deduplication, namely for providing pointer extraction &DFHeapSizeCtxset membership checks, with theDFHeapSizeimplementations onArcbacked types using the new helpersAre these changes tested?
Yes, the below are passing:
Are there any user-facing changes?
No