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

Reduce number of allocations when creating a Gc<T> #28

Open
bill-myers opened this issue Jun 11, 2020 · 5 comments
Open

Reduce number of allocations when creating a Gc<T> #28

bill-myers opened this issue Jun 11, 2020 · 5 comments
Labels
T-optimization Something is slower than it needs to be

Comments

@bill-myers
Copy link

bill-myers commented Jun 11, 2020

Currently it seems that allocating a Gc<T> requires a whopping 4 heap allocations, of the T itself, a GcHandle, a GcData and a Lockout.

There seems to be no reason why a design can't be done with just 1 allocation and with a 1-pointer wide Gc<T>, by removing GcHandle and using Arc<GcData> directly instead of Arc<GcHandle> pointing to Arc<GcData>, and putting the Lockout and data inside the GcData.

@Others Others self-assigned this Jun 11, 2020
@Others Others added the T-optimization Something is slower than it needs to be label Jun 11, 2020
@Others
Copy link
Owner

Others commented Jun 11, 2020

As you can probably tell, I optimized for ergonomics, then collection performance, and have barely looked at optimizing memory overhead.

I'm not sure your idea works. We need to track handles with unique identifiers, which means that we must allocate twice. (Once for the handle, and once for the data.) Gc<T> can't be one pointer wide because it wants a direct pointer to the data (for performance reasons), and it needs to know what handle it is associated with.

Making a GcData<T> could technically only allocate once, if we inlined the T into the GcData

The allocation for the Lockout could definitely be removed (just store it inline in the GcData), but it'd make the code bit grosser.

I may break this into a bunch of issues, since this is touching on a lot of different problems with the code. This is a very new library after all :)

@Others Others changed the title Fix extreme memory inefficiency Reduce number of allocations when creating a Gc<T> Jun 11, 2020
@Others
Copy link
Owner

Others commented Jun 16, 2020

Okay we're down to 3 allocations after #34. I think we can go down to two, but it's slightly tricky because of how deallocating currently works. I think removing that allocation should be done in conjunction with #23, because it will involve a refactoring of the deallocation logic.

Also I'm not sure this is actually the slowest part of Gc::new. I would expect inserting into the concurrent hash tables is the slowest part.

@Others Others removed their assignment Aug 6, 2020
@Others
Copy link
Owner

Others commented Feb 28, 2021

Still tracking this. I think that this is probably more of an issue now that I got rid of the concurrent hash tables (since the speed of Gc::new is now probably more tied up to these two allocations).

@Others
Copy link
Owner

Others commented Feb 28, 2021

Another complicating factor is the new support for unsized data. I found that compelling, but it complicates this since embedding unsized data in the GcData would be really really annoying

@wusyong
Copy link

wusyong commented Jun 30, 2022

Is it still 3 allocations? I would like to give it a try and work with #23 at the same time. Is there any suggestion I could get some insights first?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-optimization Something is slower than it needs to be
Projects
None yet
Development

No branches or pull requests

3 participants