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

Performance issues during traversal #100

Open
big-uncle opened this issue Jun 24, 2021 · 2 comments
Open

Performance issues during traversal #100

big-uncle opened this issue Jun 24, 2021 · 2 comments

Comments

@big-uncle
Copy link

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

@big-uncle
Copy link
Author

big-uncle commented Jun 24, 2021

// 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 (m ConcurrentMapShared) GetItems() map[string]interface{} {
	return m.items
}

@big-uncle big-uncle reopened this Jun 24, 2021
@jamelt
Copy link

jamelt commented Oct 21, 2021

@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.

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

No branches or pull requests

2 participants