Skip to content

Use precompiled struct methods for pack, unpack data - #266

Merged
brian-brazil merged 1 commit into
prometheus:masterfrom
umax:struct-usage-improvements
Apr 5, 2018
Merged

brian-brazil merged 1 commit into
prometheus:masterfrom
umax:struct-usage-improvements

Conversation

@umax

@umax umax commented Apr 4, 2018

Copy link
Copy Markdown
Contributor

Notes for struct usage optimizations: https://docs.python.org/2/library/struct.html#classes
Regarding string formatting:

In [1]: %timeit '%s' % 1
14.7 ns ± 0.325 ns per loop (mean ± std. dev. of 7 runs, 100000000 loops each)

In [2]: %timeit '{0}'.format(1)
134 ns ± 2.93 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

Comment thread prometheus_client/core.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

put an _ in front of these so they aren't exported

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment thread prometheus_client/core.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Explain what you're doing a bit more. Not everyone will have seen the relevant talks by Raymond Hettinger

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know why this works, but someone reading this code might not. A quick comment will help future readers of the code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

@umax
umax force-pushed the struct-usage-improvements branch from 223267c to 1b295a7 Compare April 4, 2018 08:47
@umax
umax force-pushed the struct-usage-improvements branch from 1b295a7 to adaad2d Compare April 4, 2018 13:02
@brian-brazil
brian-brazil merged commit a5e7c4e into prometheus:master Apr 5, 2018
@brian-brazil

Copy link
Copy Markdown
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants