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 GC overhead by using custom memory allocator #8

Closed
mangalaman93 opened this issue Mar 27, 2019 · 14 comments
Closed

Reduce GC overhead by using custom memory allocator #8

mangalaman93 opened this issue Mar 27, 2019 · 14 comments
Labels
kind/enhancement Something could be better. priority/P2 Somehow important but would not block a release. status/accepted We accept to work on it.
Milestone

Comments

@mangalaman93
Copy link
Contributor

No description provided.

@mangalaman93 mangalaman93 added the kind/enhancement Something could be better. label Mar 27, 2019
@mangalaman93 mangalaman93 added this to the future milestone Mar 27, 2019
@ben-manes
Copy link

You will likely want to use a SeqLock when reading from / writing into the byte[] value. See Java's StampedLock API and internal algorithm notes for details

@souvikhaldar
Copy link

What is the GC overhead here?

@souvikhaldar
Copy link

souvikhaldar commented Nov 8, 2019

Are you planning on using memory ballast for reducing GC cycles? @mangalaman93

@erikdubbelboer
Copy link

Memory ballast doesn't make sense for ristretto and if it would make sense it's still something the application should do by itself, not the library.

@erikdubbelboer
Copy link

A custom memory allocator doesn't make sense either seeing as ristretto only stores interface{}. You could build a library on top of ristretto that serializes all data you put in into []byte that uses a custom allocator. But that's not the use case for ristretto. ristretto allows you to put in unseralizable data like channels as well.

@souvikhaldar
Copy link

My intention here is to understand what is the overhead of GC that this issue tries to reduce by the memory allocator. @mangalaman93
When I see someone trying to reduce unnecessary GC cycles to keep heap memory size in check (which isn't much important) I can't help but suggest using memory ballast. Sure there needs to be fine-tuning further and it's better not to do it at the library level, but it's pretty much doable and helpful nonetheless. Also, I think it is going to be part of Go runtime soon (refer- golang/go#23044) . @erikdubbelboer Can you suggest some alternative?

@erikdubbelboer
Copy link

I don't think this issue was created to reduce the amount of GC cycles. This is not something a custom memory allocator would change.

What this issue is about is that you want to have less pointers for the GC to check, so it runs faster. Using a custom memory allocator you can put everything in a []byte so GC only has to check 1 pointer to the []byte instead of all pointer to all objects.

@souvikhaldar
Copy link

I see. I would love to learn more about it. Is this what you are talking about? https://segment.com/blog/allocation-efficiency-in-high-performance-go-services/

If not, can you suggest some reading?

@erikdubbelboer
Copy link

Both bigcache and https://github.com/coocood/freecache#how-it-is-done use different techniques to avoid having too many pointers.

@proyb6
Copy link

proyb6 commented Dec 2, 2019

@erikdubbelboer I think you know VictoriaMetric have FastCache repo as well, is it a good example for reference reading?
ethereum/go-ethereum#19971

@erikdubbelboer
Copy link

Yes fastcache is also very good. I didn't mention it because it has a bit more complex way to deal with lowering GC overhead.

@martinmr
Copy link
Contributor

@mangalaman93 is this issue still relevant?

@mangalaman93
Copy link
Contributor Author

I think so, because the way Ristretto stores data is all pointers. The more the data, GC effects are gonna be more and more visible.

@martinmr martinmr added priority/P2 Somehow important but would not block a release. status/accepted We accept to work on it. labels Apr 15, 2020
@minhaj-shakeel
Copy link
Contributor

Github issues have been deprecated.
This issue has been moved to discuss. You can follow the conversation there and also subscribe to updates by changing your notification preferences.

drawing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Something could be better. priority/P2 Somehow important but would not block a release. status/accepted We accept to work on it.
Development

No branches or pull requests

7 participants