ranger: Improve intsRanger performance #202
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This uses an indirection trick to avoid an allocation in intsRanger.Range call, signficantly improving its performance during iteration.
The trick involves calling reflect.ValueOf on the address of the field instead of using its concrete value. This avoids an allocation performed by the Go runtime to convert the int value to an interface value.
In order to use this trick, the interpretation of the 'i' field needed to be changed from "next index" to "previous index" and its initialization needed to be offset by -1.
Following is the impact of this change in the relevant benchmark:
Additionally, it adds a benchmark to assert custom renderer performance.
It's now possible to execute templates with guaranteed zero memory allocations (during execution) by using a combination of int and custom rangers and either simple field access or custom renderers.