Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Offset calculated on every iteration #34

Closed
davebryson opened this issue May 7, 2021 · 4 comments · Fixed by #35
Closed

Offset calculated on every iteration #34

davebryson opened this issue May 7, 2021 · 4 comments · Fixed by #35
Assignees
Labels
good first issue Good for newcomers

Comments

@davebryson
Copy link

Just noticed this while working through the code. Does this need to be calculated on every iteration?

https://github.com/lazyledger/smt/blob/master/smt.go#L289

When I move it above the for loop, all test still pass.

@adlerjohn
Copy link
Member

Permalink:

https://github.com/lazyledger/smt/blob/54602cb54f9753ea062755e046003b73b47922d0/smt.go#L289

The Go compile is smart enough to perform loop invariant code motion. I don't know if it does in this case, but it's not a guarantee that performing the optimization by hand would actually be doing anything that isn't already being done by the compiler. The generated assembly would have to be analyzed to determine if the compiler is performing the optimization or not.

@liamsi
Copy link
Member

liamsi commented Jun 8, 2021

@davebryson @adlerjohn does it make sense to analyze the generated assembly in this case? Also, is there anything else that needs further clarification? Otherwise, I'd close this issue.

@adlerjohn
Copy link
Member

I can implement the change, since it's trivial and doesn't hurt.

@liamsi
Copy link
Member

liamsi commented Jun 8, 2021

Yeah, looking at the line in question: independent from how the go compiler handles this, I think it makes sense to move this for readability (to save others the cognitive overhead and time thinking about this).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants