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

Improving object allocation for (positional) parameter binding #1092

Merged
merged 3 commits into from
Sep 12, 2023

Conversation

mdonkers
Copy link
Contributor

Summary

I noticed very high object allocation count with the ClickHouse Go client in our code. While with binding the parameters to a String this is logical to some extend, I found some easy improvements:

  1. Mis-use of the strings.NewReplacer, as this instance is meant to be re-used but a new instance was created all the time
  2. Replacement of positional arguments in the query string, for which not really a regex is needed. Specifically to find \? cases, two regex replacements were nested, creating a temporary string instance that shouldn't be needed. So I changed to code to a 'simple' loop that copies byte sequences.

Original object allocation:
2023-09-11-10-21-14_1899x227

Allocations after just changing strings.NewReplacer to be called once:
2023-09-11-10-21-56_1906x257

Final result:
2023-09-11-17-13-17_1901x169

(of course above numbers are case specific, but for our instance this meant going from being responsible for 70% of object allocations to around 30%)

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG
  • For significant changes, documentation in https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials

Copy link
Contributor

@jkaflik jkaflik left a comment

Choose a reason for hiding this comment

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

@mdonkers this is great! Thanks. Please remove changes to CHANGELOG.md. It's generated automatically. We have quite unstable runners nowadays - i will take a look.

@mdonkers
Copy link
Contributor Author

@mdonkers this is great! Thanks. Please remove changes to CHANGELOG.md. It's generated automatically. We have quite unstable runners nowadays - i will take a look.

Reverted the changelog and squashed the commits to only have the actual changes in there.

@jkaflik jkaflik merged commit 8b481ed into ClickHouse:main Sep 12, 2023
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants