-
-
Notifications
You must be signed in to change notification settings - Fork 119
Fix multiple unnecessary calls to strnom::skip_whitespace #226
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
Conversation
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.
Thanks!
Some notes below.
src/fallback.rs
Outdated
if input.is_empty() { | ||
break; | ||
} |
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.
Is this needed? It looks like input.is_empty()
would only be true at most once in the entire parse so I don't see a way that this would affect performance. If you omit it, the next loop iteration will fail to parse a token_tree and break, which is still correct behavior.
src/fallback.rs
Outdated
let input_no_ws = skip_whitespace(input); | ||
if input_no_ws.rest.len() == 0 { | ||
break; | ||
} | ||
if let Ok((a, tokens)) = doc_comment(input_no_ws) { | ||
if let Ok((a, tokens)) = doc_comment(input) { | ||
input = a; | ||
trees.extend(tokens); | ||
continue; | ||
} | ||
|
||
let (a, tt) = match token_tree(input_no_ws) { | ||
let (a, tt) = match token_tree(input) { |
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.
Help me understand this change: This causes all whitespace and comments to be parsed twice as many times, doesn't it? The previous behavior made 3 calls to skip_whitespace but only 1 of them would do any work. The new behavior makes 2 calls to skip_whitespace where the second one redoes all the work already done by the first one. Seems like which one is better would depend heavily on the characteristics of the input.
Instead we might want to split some of these functions like what we have for symbol_leading_ws
vs symbol
below, and always call the right one depending on whether whitespace has already been processed at the call site.
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.
Yes, it should go where it was.
I want to remove the call to skip_whitespace
at spanned
. I just removed it to make sure it worked since the logic is complex.
src/fallback.rs
Outdated
@@ -919,7 +919,7 @@ named!(group -> Group, alt!( | |||
)); | |||
|
|||
fn symbol_leading_ws(input: Cursor) -> PResult<TokenTree> { |
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 function should be deleted if it no longer does anything different from symbol
.
Even though the use of Old
New
|
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.
Thank you!
#126
cargo build --release valgrind --tool=callgrind target/release/bench_proc callgrind_annotate --auto=yes callgrind.out.*
This one step, it eat about 300M ir.
I can improve it much more but it needs a refactor, the
alt!
macros they are not efficient and the common logic is repeated many times, the most calledskip_whitespace
but there are also others likefallback::token_kind
,fallback::op_char
...If you like, I continue.