-
Notifications
You must be signed in to change notification settings - Fork 133
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
Performance improvements to StatSerializer #156
Conversation
Another performance improvement for review when you have a chance, @kbogtob. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, i think using string interpolation should help here, seems like we've preserved all the same logic and case handling
# replace reserved chars (: | @) with underscores. | ||
f.tr!(':|@', '_') | ||
if name.is_a?(String) | ||
# DEV: gsub is faster than dup.gsub! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting given the extra allocation(?) in gsub!
, do we know why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me 👍
(added a question about gsub!
but feel free to merge IMO)
# replace reserved chars (: | @) with underscores. | ||
f.tr!(':|@', '_') | ||
if name.is_a?(String) | ||
# DEV: gsub is faster than dup.gsub! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting given the extra allocation(?) in gsub!
, do we know why?
Similar to #155, this PR reduces the overhead of submitting metrics by
dogstatsd-ruby
.Most of the gains came from avoiding successive string resizing performed by String#<<.
Another large gain came from replacing
string.dup.gsub!
withstring.gsub
in#formated_name
:A smaller gain came from removing the use of
tap
in two locations:There were no memory improvements performed.
Benchmark results
Before
After
Results