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

Warning about passing lock by value in xsync.Range function. Is that expected? #144

Open
mernesteze-eng opened this issue Jul 22, 2024 · 1 comment
Labels
question Further information is requested

Comments

@mernesteze-eng
Copy link

mernesteze-eng commented Jul 22, 2024

Currently getting this warning on the range function, is that expected

'func' passes a lock by the value: type 'globals.RequestArtifacts' contains 'sync.WaitGroup' contains 'interface{}' which is 'sync.Locker' 

Here's some preceding context

test := xsync.NewMapOf[string, globals.RequestArtifacts]()
	test.Range(func(key string, value globals.RequestArtifacts) bool {

When I change test schema structure to

test := xsync.NewMapOf[string, *globals.RequestArtifacts]()
	test.Range(func(key string, value *globals.RequestArtifacts) bool {

warning clears. Do our xsync generic types need to be pointers to structs instead of the struct itself? Do we lose or not gain any performance boost by using pointers?

@puzpuzpuz
Copy link
Owner

Do our xsync generic types need to be pointers to structs instead of the struct itself? Do we lose or not gain any performance boost by using pointers?

Internally, key and value is stored in the following struct:

type entryOf[K comparable, V any] struct {
	key   K
	value V
}

So, if the struct is "simple" (no mutexes), you should use the struct and it will be copied. This is preferred for performance reasons. If not, pointers must be used.

@puzpuzpuz puzpuzpuz added the question Further information is requested label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants