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

interp: avoid redundant array copies #253

Merged
merged 1 commit into from
Jun 23, 2018
Merged

interp: avoid redundant array copies #253

merged 1 commit into from
Jun 23, 2018

Conversation

quasilyte
Copy link
Contributor

Every range over array that binds a value does a full copy of array being iterated.
The workaround is to either use &x instead x or do index-only range.

In this case, shellOptsTable (192 bytes) is copied before each changed range stmt.
Not it does only pointer copy. Compiler optimizes accesses, so there is no
drawbacks for this. (And there is close to no difference for sizes of < 48 byte.)

See: https://github.com/cristaloleg/go-advices

Every range over array that binds a value does a full copy of array being iterated.
The workaround is to either use `&x` instead `x` or do index-only range.

In this case, shellOptsTable (192 bytes) is copied before each changed range stmt.
Not it does only pointer copy. Compiler optimizes accesses, so there is no
drawbacks for this. (And there is close to no difference for sizes of < 48 byte.)

See: https://github.com/cristaloleg/go-advices
@quasilyte
Copy link
Contributor Author

This is minor issue and I'm not sure these functions are anywhere near hot paths (probably they don't).
Sending just in case.

Copy link
Owner

@mvdan mvdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt this is a problem now since it's small, but it sounds good in principle. And the table is going to get bigger.

@mvdan mvdan merged commit e32dca9 into mvdan:master Jun 23, 2018
@quasilyte quasilyte deleted the quasilyte/rangeExprCopy branch June 23, 2018 21:37
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

Successfully merging this pull request may close these issues.

None yet

2 participants