-
Notifications
You must be signed in to change notification settings - Fork 188
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
src/encoder/text: Optimize metric formatting #327
Conversation
Signed-off-by: Max Inden <mail@max-inden.de>
Instead of going through `write!` which calls `write_fmt` use `write_all` directly skipping the additional formatting overhead. Signed-off-by: Max Inden <mail@max-inden.de>
Within `escape_string` instead of always allocating a new String and iterating through each character one-by-one, first check whether the input string needs any escaping, if not, return without any allocation. If it does need escaping, start from the first occurence. Signed-off-by: Max Inden <mail@max-inden.de>
Signed-off-by: Max Inden <mail@max-inden.de>
LGTM, but leaving some room for others' feedback. |
@breeswish yes |
Any further comments on this patch? @breeswish in case there are no objections, do you want me to merge my own pull-request, or rather always have someone other than the author click the merge button? |
I am guessing there are no objections to this patch. @lucab @breeswish could one of you approve this pull request? |
@mxinden stamped |
@lucab Feel free to just merge PRs :) |
This pull request addresses the low-hanging-fruits within
src/encoder/text.rs
with the following commits:src/benches&src/bin: Add basic text encoder benchmark
src/encoder/text: Use
write_all
instead ofwrite_fmt
Instead of going through
write!
which callswrite_fmt
usewrite_all
directly skipping the additional formatting overhead.src/encoder/text: Use regex crate to determine if escaping is needed
Within
escape_string
instead of always allocating a new String and iterating through each character one-by-one, first check whether the input string needs any escaping, if not, return without any allocation. If it does need escaping, start from the first occurence.Benchmark results on a
Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
:CPU flamegraph before:
CPU flamegraph after:
Memory allocation flamegraph before:
Memory allocation flamegraph after: