Performance improvement: Non-recursively drop TokenStreams with a visitor #489
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello! I noted in a profiler on my system that while running the benchmarks in the
syn
repository that an outsided amount of time is spent in the non-recursiveDrop
implementation forTokenStream
that was introduced in #232 to solve the stack overflow noted in #55. A large portion of this time can be removed by using a visitor pattern to drop segments of theTokenStream
instead of flattening groups into the innerVec
.This adds some complexity which may be undesirable, but (at least in my tests) it does yield good results when repeatedly running those benchmarks.
Running
syn
srust
benchmark withproc-macro2 1.0.92
:Running
syn
srust
benchmark with this fork:This yields about a 7% performance improvement in the
tokenstream_parse
test and a 12% performance improvement in thesyn_parse
test on my system.Opening as a draft to get feedback and testing with other use-cases. If no regressions are found, I will mark it ready for review. Thanks!