Closed adriandelgado closed 1 year ago
Could you add a before and after performance delta from hyperfine.
Not much difference. But this is my first step to ease some bigger changes later. Also, I think these functions are not changed very often.
The perf. benefits of this PR get more noticeable after some of the other proposed changes. The change from &Vec<(&str, String)>
to &[(&str, String)]
is the most important because it unlocks more possibilities without any inconveniences.
The change from
&Vec<(&str, String)>
to&[(&str, String)]
is the most important because it unlocks more possibilities without any inconveniences.
Yes. It should probably have had a &[]
signature regardless of anything else.
Oops. The first force-push had my notes haha. Please ignore those.
I still don't like the write_all()
part of this change and don't see any improvement outside the margin of error so I'd prefer if you dropped that part of the PR and just restrict it to the changes in the reset()
and escape_string()
functions.
This question and the link in the answer suggests that write()
and write_all()
are the same in this context: https://users.rust-lang.org/t/io-write-write-vs-io-write-write-all/6341
Don't update the test section either. I want some of the tests to use vec()
and I will fix the to_owned()
as part of a general cleanup.
This question and the link in the answer suggests that
write()
andwrite_all()
are the same in this context
Yes, they are the same. However the write!
macro uses write_fmt
which need to pass through the formatter which has more complex machinery. In this case, I didn't saw a measurable difference though so I removed those changes. It probably gets optimized away by the compiler.
Merged. Thanks.
I also added the vec!
to []
change to main. If you don't have any other performance changes planned in the short term I'll publish these changes in a updated version and get back to the general porting.
No relevant perf. changes left for now. I'm thinking of helping porting some features, too. For example, we need the set_labels_percentage at work.
"Help" on porting usually just gets in my way but I'm happy to port that feature next.
&Vec<(&str, String)>
to&[(&str, String)]
. This doesn't need any changes to the rest of the codebase and improves flexibility by allowing us to use arrays instead of vectors..chars().enumerate()
to.char_indices()
to avoid re-iterating and collecting.