DEV Community

Discussion on: My journey optimizing the Go Compiler

Collapse
 
craigmc08 profile image
Craig McIlwrath

I was looking at the comments on that pull request and the discussion about side effects in the map caught my eye. If I understood it right, it wasn't an issue because this optimization doesn't happen in that case.

Did you give any thought to applying a similar optimization when only the index is constant? Something like evaluating all of the values in the map and then returning the proper value based on the constant index?

Collapse
 
segflow profile image
Assel Meher • Edited

That's actually an idea I thought of when I read the reviewer's comment. And looks like a good one, I also believe that only function calls (like the given example in the PR) can have side effects, probably there are others but can't think of them right now.