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

graphite: reduce the memory used by GraphiteParser.Parse() by ~80% #5841

Merged
merged 3 commits into from
Jun 14, 2019

Conversation

charlievieth
Copy link
Contributor

The commit reduces the amount of memory used by GraphiteParser.Parse() by 80% and increases performance by 30%. Honestly, this would be more efficient if we stepped through buf line-by-line but this improvement is good enough to justify a PR.

benchmark             old ns/op     new ns/op     delta
BenchmarkParse-16     1825          1235          -32.33%

benchmark             old allocs     new allocs     delta
BenchmarkParse-16     24             20             -16.67%

benchmark             old bytes     new bytes     delta
BenchmarkParse-16     5200          896           -82.77%

Required for all PRs:

  • [ x ] Signed CLA.
  • [ x ] Associated README.md updated.
  • [ x ] Has appropriate unit tests.

Also, this codebase and in particular anything on the statsd path spends quite a bit of time and memory splitting strings. Fixing this would lead to some pretty easy perf wins.

The commit reduces the amount of memory used by `GraphiteParser.Parse()`
by 80% and increases performance by 30%.  Honestly, this would be more
efficient if we stepped through `buf` line-by-line but this improvement
is good enough to justify a PR.

```
benchmark             old ns/op     new ns/op     delta
BenchmarkParse-16     1825          1235          -32.33%

benchmark             old allocs     new allocs     delta
BenchmarkParse-16     24             20             -16.67%

benchmark             old bytes     new bytes     delta
BenchmarkParse-16     5200          896           -82.77%
```
Copy link
Contributor

@glinton glinton left a comment

Choose a reason for hiding this comment

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

I say go all-in and step through line by line, but this is great!

@glinton glinton added the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label May 13, 2019
@charlievieth
Copy link
Contributor Author

Will investigate going line by line and will update the PR if it improves perf or note why it didn't (and will remove my comment if thats the case).

This improves the performance of e0dcfc5 by roughly ~5%.

```
benchmark            old ns/op     new ns/op     delta
BenchmarkParse-8     1692          1603          -5.26%

benchmark            old allocs     new allocs     delta
BenchmarkParse-8     20             19             -5.00%

benchmark            old bytes     new bytes     delta
BenchmarkParse-8     896           880           -1.79%
```
@charlievieth
Copy link
Contributor Author

@glinton updated to step through the buffer line-by-line the improves perf by roughly ~5%.

Copy link
Contributor

@glinton glinton left a comment

Choose a reason for hiding this comment

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

Awesome!

}
if n == -1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Kind of a nitpick, but I'd feel safer if this was n < 0. Your call

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doesn't hurt, changed both.

The return of bytes.IndexByte() is -1 if the byte being searched for is
not found, but I'm changing the check to 'n < 0' to resolve a nit and
guard against this breaking in the future: say by someone modifying n
within this loop (note: don't do that).
@danielnelson danielnelson added this to the 1.12.0 milestone Jun 14, 2019
@danielnelson danielnelson merged commit b35beb2 into influxdata:master Jun 14, 2019
bitcharmer pushed a commit to bitcharmer/telegraf that referenced this pull request Oct 18, 2019
athoune pushed a commit to bearstech/telegraf that referenced this pull request Apr 17, 2020
idohalevi pushed a commit to idohalevi/telegraf that referenced this pull request Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants