Skip to content

Reuse existing scope ids in register_user_scopes#269

Merged
emilk merged 1 commit intoEmbarkStudios:mainfrom
Azkellas:register_user_scopes_leak
Feb 23, 2026
Merged

Reuse existing scope ids in register_user_scopes#269
emilk merged 1 commit intoEmbarkStudios:mainfrom
Azkellas:register_user_scopes_leak

Conversation

@Azkellas
Copy link
Contributor

Checklist

  • I have read the Contributor Guide
  • I have read and agree to the Code of Conduct
  • I have added a description of my changes and why I'd like them included in the section below

Description of Changes

Currently, GlobalProfiler::register_user_scopes requires users to track the scopes details to avoid bad memory leaking. This is effectively asking the users to keep their own ScopeCollection when the data is already stored internally.

I'm aware that the GlobalProfiler scope_collection is private and the design is here intentionally but the comment mentions the frame views and, as far as I know, external applications can't create frames without first creating the ids.

To make the api nicer for external applications, I make register_user_scopes first check if the scope name is already in the collection, and only create a new id if this is the first time encountering the scope label. Another solution would be to make the scope collection accessible (read only) from outside.

Note: I'm not super familiar with the puffin codebase and overall architecture, I might be missing some subtleties.

@Azkellas
Copy link
Contributor Author

See Wumpf/wgpu-profiler#104 for what motivated this pull request.
wgpu-profiler outputs gpu timings to puffin. The current implementation does not cache scope ids, which leads to massive leakage, and adding a cache is an unnecessary burden to the end user.

@Azkellas
Copy link
Contributor Author

On a side note, this is out of scope for this PR and probably for puffin as well, but since the GPU timings are available late, the current solution is to add another puffin profiler to app using gpu timings with puffin.

Is there a way to retrospectively add scopes to a previous frame or would that be too much of a change in design / not the puffin philosophy?

Copy link

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

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

makes sense to me. @emilk any chance this could be in a patch release?

@emilk emilk merged commit 0625740 into EmbarkStudios:main Feb 23, 2026
7 of 8 checks passed
@emilk
Copy link
Collaborator

emilk commented Feb 23, 2026

any chance this could be in a patch release?

Isn't this a breaking change? :/

@Wumpf
Copy link

Wumpf commented Feb 23, 2026

hmmmmmm I suppose technically it is since the returned ids are different

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants