Skip to content
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

wrap Arc<Backtrace> in Option, saving memory when backtraces are disabled #252

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Firestar99
Copy link

@Firestar99 Firestar99 commented Oct 30, 2024

This PR wraps all Arc<Backtrace> in Option, as to not have to allocate an Arc of a disabled Backtrace each time GPU memory is allocated with backtraces are disabled. This is probably a premature optimization, but it was so easy to implement I couldn't resist :D

I only tested the vulkan implementation and visualizer on Linux, I hope CI catches issues for the other platforms.

Copy link
Collaborator

@manon-traverse manon-traverse left a comment

Choose a reason for hiding this comment

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

Looks like a nice small optimization. Thanks for your contribution! :D

@MarijnS95
Copy link
Member

I recall checking long ago that Backtrace::Captured { .. } used to be quite small back in the day, is that no longer the case?

Regardless, this saves us some bytes in the Arc too so I guess it's nice to have. There's nothing to do about the ambiguity between None and Some(Arc::new(Backtrace::Disabled)) but it is what it is :)

Copy link
Member

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

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

Looking at this PR I still wonder why the Backtrace is wrapped in an Arc; in e45e25a I wrote that that is to support "Cloneing" the Backtrace, but glancing at the implementation that is only because of mistakes in the ownership transfer in our fn allocate() code and copies for AllocationReport which should either not receive a Backtrace at all, or borrow it temporarily while the caller can view the backtrace.

src/allocator/free_list_allocator/mod.rs Outdated Show resolved Hide resolved
@Firestar99
Copy link
Author

why the Backtrace is wrapped in an Arc

I don't have the time right now to investigate that further, feel free to do that yourself or leave the PR as is.

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