You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we are traversing frequently, using IterBuffered() will generate a lot of memory garbage, which will cause a lot of burden on the GC of the program. At this time, we need to traverse externally, so we have to provide the items method
The text was updated successfully, but these errors were encountered:
// return items to the outside// When external traversal, it is helpful to reduce heap memory allocation// When the external traversal is very frequent, the external traversal by itself will have better performance than using IterBuffered()//use example:// for _, shard := cmap {// shard.RLock()// for _, val := range shard.GetItems() {// //to do something...// }// shard.RUnlock()// }func (mConcurrentMapShared) GetItems() map[string]interface{} {
returnm.items
}
@big-uncle i would strongly discourage that get items method. i had a similar method in my program and it wreaked havoc on my garbage collector. the absolute best bet is to use IterCb which is similar to the Range method on sync.Map. That will eliminate any unnecessary heap allocations and allow you to iterate through the items without having to spin up a goroutine to push items to a channel.
When we are traversing frequently, using IterBuffered() will generate a lot of memory garbage, which will cause a lot of burden on the GC of the program. At this time, we need to traverse externally, so we have to provide the items method
The text was updated successfully, but these errors were encountered: