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

Reverse entry iterator pool #2064

Merged
merged 3 commits into from
May 11, 2020
Merged

Conversation

cyriltovena
Copy link
Contributor

The iter.NewReversedIter was causing a lot of allocs. This uses a pool and remove the labels string since we never needed it.

benchcmp:

benchmark                        old ns/op     new ns/op     delta
BenchmarkBackwardIterator-16     15943073      14537418      -8.82%

benchmark                        old allocs     new allocs     delta
BenchmarkBackwardIterator-16     47217          47225          +0.02%

benchmark                        old bytes     new bytes     delta
BenchmarkBackwardIterator-16     27444423      23664350      -13.77%

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
@cyriltovena cyriltovena changed the title Reveriter pool Reverse entry iterator pool May 11, 2020
Copy link
Member

@owen-d owen-d left a comment

Choose a reason for hiding this comment

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

Overall, lgtm once you get your tests passing. I'm a little wary of having implementations which only satisfy the EntryIterator ifc in compilation, but not in reality (returning "" for Labels()). That being said, I see this isn't the only place we do this, so I don't want to block it.

I think the long path forward may be using subset/superset interfaces i.e. type LabeledEntryIterator interface { Labels() string, EntryIterator }, but that type of refactor is way too much for this PR.

What about an adapter like

type BoundLabelsIterator struct{
  ls string
  EntryIterator
}

func (i BoundLabelsIterator) Labels() string {return i.ls}

?

@cyriltovena
Copy link
Contributor Author

Overall, lgtm once you get your tests passing. I'm a little wary of having implementations which only satisfy the EntryIterator ifc in compilation, but not in reality (returning "" for Labels()). That being said, I see this isn't the only place we do this, so I don't want to block it.

I wasn't sure how to do this properly, I just catched that with labels it's a bit slower, not much but with the amount of those struct allocated it can make a difference.

@cyriltovena cyriltovena merged commit a8b94ae into grafana:master May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants