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.
This pull request makes the parser faster.
This pull request includes two hacks.
First, it reduces
StringScanner#charpos
method calls because it is heavy method.https://github.com/ruby/strscan/blob/d0c82c20c64323c45ee275f09e5a951a291f1ee2/ext/strscan/strscan.c#L442-L453
profiling
(By the way, we need to modify parser.rb to display the line-level profiling by stackprof.
module_eval(<<'...end parser.y/module_eval...', __FILE__, __LINE__ + 1)
)Second, it replaces
StringScanner#charpos
withStringScanner#pos
if the source only contains ASCII characters.it improves performance if the content is ASCII only. But parsing will be slow if the content is not ASCII only.
I think most RBS files are ASCII only, so this hack improves performance on the whole.
Benchmark
before
Reduce charpos calls
This benchmark doesn't include
ascii_only?
hack.1.22x faster for almost ascii case, and 1.27x faster for unicode case.
Reduce charpos calls + ascii_only? hack
The result of this pull request.
1.58x fasterfor almost ascii case, and 1.14x faster for unicode case.