Skip to content

Initial stats cleanup#1009

Open
nirandaperera wants to merge 5 commits intorapidsai:mainfrom
nirandaperera:stats-refactor
Open

Initial stats cleanup#1009
nirandaperera wants to merge 5 commits intorapidsai:mainfrom
nirandaperera:stats-refactor

Conversation

@nirandaperera
Copy link
Copy Markdown
Contributor

@nirandaperera nirandaperera commented May 1, 2026

Statistics was constructible directly (make_shared<Statistics>(false) was not equal to Statistics::disabled()), MemoryRecorder held a raw Statistics* (lifetime hazard noted by an existing TODO), provider statistics() accessors returned shared_ptr by value (atomic refcount bumps on hot paths), and secondary objects like AllGather redundantly carried their own statistics_ member already reachable through the buffer resource / context.

In this PR, following changes were made

  • Make Statistics constructible only through factory methods (create(), from_options(), disabled()); the public ctor is removed and disabled() is now the canonical singleton for the disabled case.
  • Inherit Statistics from std::enable_shared_from_this so MemoryRecorder owns a shared_ptr<Statistics> instead of a raw pointer; recorder no-ops when stats are disabled.
  • Introduce a StatisticsProvider concept and have providers (BufferResource, ProgressThread, streaming::Context) return std::shared_ptr<Statistics> const& from statistics(); each provider static_asserts the concept.
  • Drop the redundant statistics parameter and statistics_ member from coll::AllGather (and its Python binding); secondary classes now derive their Statistics from the provider they already receive.

Related to #1008

Depends on #1003

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 1, 2026

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@nirandaperera nirandaperera mentioned this pull request May 1, 2026
3 tasks
Comment thread cmake/cpm_override_packages.json Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Committed in error?

RmmResourceAdaptor mr,
std::optional<PinnedMemoryResource> pinned_mr = PinnedMemoryResource::Disabled
);
static std::shared_ptr<Statistics> create(bool enabled = true);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: What does having a create static method buy us over a constructor?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

factory methods allows us to safely use std::enable_shared_from_this, where we can pass a shared_ptr to memory recorder rather than a ptr

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're doing this, let's return a const & reference to the shared ptr?

@nirandaperera
Copy link
Copy Markdown
Contributor Author

@wence- this is a draft on top of #1003. Let's merge it first, then I will rebase this.

Signed-off-by: niranda perera <niranda.perera@gmail.com>

remove stats from allgather

Signed-off-by: niranda perera <niranda.perera@gmail.com>

stats provider concept

Signed-off-by: niranda perera <niranda.perera@gmail.com>

WIP

Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
@nirandaperera nirandaperera added improvement Improves an existing functionality non-breaking Introduces a non-breaking change labels May 7, 2026
@nirandaperera nirandaperera marked this pull request as ready for review May 7, 2026 16:40
@nirandaperera nirandaperera requested review from a team as code owners May 7, 2026 16:40
@nirandaperera
Copy link
Copy Markdown
Contributor Author

nirandaperera commented May 7, 2026

@wence- this is ready for review now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improves an existing functionality non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants