-
Notifications
You must be signed in to change notification settings - Fork 21.5k
all: avoid copying arrays in loops #17265
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
all: avoid copying arrays in loops #17265
Conversation
|
It's not slice copy, but rather array copy, if we're talking about |
|
@quasilyte thanks, I've fixed title & description. |
|
@cristaloleg Are you sure this isn't automatically optimized by the compiler? Would seem really weird if it actually did a full on copy of the arrays. |
|
@karalabe I'm sure and tried to fix it in the compiler. Possible to be optimized, but you need to know that loop is never executed from different threads, otherwise you get different results if array is modified. By go specs, it must be a full copy there. |
|
There is an issue for that: golang/go#15812 |
|
Fair enough! |
karalabe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Thanks to everyone! |
Avoid copying arrays of heavy structs (100 bytes and more) in loops. Found by the go-critic linter.
Linter's log: