Skip to content

Commit 6a3ee53

Browse files
jensjohaCommit Queue
authored andcommitted
[parser] Don't use late variables in the scanner
The usage of late variables become an access, a comparison to a marker, and a conditional jump. Having it be non-null and non-late it's just an access. Running aot compiled scanner benchmarks on pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart with `--bytes` gives: ``` N Min Max Median Avg Stddev x 25 149.49816 154.67461 153.12174 153.03484 1.2430919 + 25 153.82654 157.77314 156.45323 156.15451 1.1301418 Difference at 95.0% confidence 3.11967 +/- 0.675708 2.03853% +/- 0.441538% (Student's t, pooled s = 1.18796) ``` And running the benchmarker with `--cache --silent --iterations=50` on the scanner benchmark with the same parameters gives: ``` Comparing snapshot 1 with snapshot 2 msec task-clock:u: -1.9158% +/- 0.3843% (-48.87 +/- 9.80) cycles:u: -1.9652% +/- 0.3719% (-218241604.28 +/- 41302487.04) instructions:u: -0.4735% +/- 0.0000% (-116299496.56 +/- 182.39) seconds time elapsed: -1.9132% +/- 0.3834% (-0.05 +/- 0.01) seconds user: -2.0074% +/- 0.4009% (-0.05 +/- 0.01) Comparing snapshot 1 with snapshot 2 msec task-clock:u: -2.1237% +/- 0.2726% (-54.21 +/- 6.96) L1-icache-load-misses: -6.2140% +/- 3.3961% (-268165.40 +/- 146560.98) LLC-loads: -0.5702% +/- 0.4680% (-6613.36 +/- 5428.54) seconds time elapsed: -2.1219% +/- 0.2728% (-0.05 +/- 0.01) seconds user: -2.0997% +/- 0.2793% (-0.05 +/- 0.01) ``` Change-Id: I38e076a2e8442e3313075eaa600114f664eb415d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/411640 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent a9ab52b commit 6a3ee53

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

pkg/_fe_analyzer_shared/lib/src/scanner/abstract_scanner.dart

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,17 @@ abstract class AbstractScanner implements Scanner {
9999
* is not exposed to clients of the scanner, which are expected to invoke
100100
* [firstToken] to access the token stream.
101101
*/
102-
final Token tokens = new Token.eof(/* offset = */ -1);
102+
final Token tokens;
103103

104104
/**
105105
* A pointer to the last scanned token.
106106
*/
107-
late Token tail;
107+
Token tail;
108108

109109
/**
110110
* A pointer to the last prepended error token.
111111
*/
112-
late Token errorTail;
112+
Token errorTail;
113113

114114
@override
115115
bool hasErrors = false;
@@ -140,26 +140,40 @@ abstract class AbstractScanner implements Scanner {
140140
int recoveryCount = 0;
141141
final bool allowLazyStrings;
142142

143-
AbstractScanner(ScannerConfiguration? config, this.includeComments,
144-
this.languageVersionChanged,
143+
AbstractScanner(ScannerConfiguration? config, bool includeComments,
144+
LanguageVersionChanged? languageVersionChanged,
145+
{required int numberOfBytesHint, bool allowLazyStrings = true})
146+
: this._(config, includeComments, languageVersionChanged,
147+
new Token.eof(/* offset = */ -1),
148+
numberOfBytesHint: numberOfBytesHint,
149+
allowLazyStrings: allowLazyStrings);
150+
151+
AbstractScanner._(ScannerConfiguration? config, this.includeComments,
152+
this.languageVersionChanged, Token newEofToken,
145153
{required int numberOfBytesHint, this.allowLazyStrings = true})
146154
: lineStarts = new LineStarts(numberOfBytesHint),
147-
inRecoveryOption = false {
148-
this.tail = this.tokens;
149-
this.errorTail = this.tokens;
155+
inRecoveryOption = false,
156+
tokens = newEofToken,
157+
tail = newEofToken,
158+
errorTail = newEofToken {
150159
this.configuration = config;
151160
}
152161

153162
AbstractScanner createRecoveryOptionScanner();
154163

155164
AbstractScanner.recoveryOptionScanner(AbstractScanner copyFrom)
165+
: this._recoveryOptionScanner(copyFrom, new Token.eof(/* offset = */ -1));
166+
167+
AbstractScanner._recoveryOptionScanner(
168+
AbstractScanner copyFrom, Token newEofToken)
156169
: lineStarts = [],
157170
includeComments = false,
158171
languageVersionChanged = null,
159172
inRecoveryOption = true,
160-
allowLazyStrings = true {
161-
this.tail = this.tokens;
162-
this.errorTail = this.tokens;
173+
allowLazyStrings = true,
174+
tokens = newEofToken,
175+
tail = newEofToken,
176+
errorTail = newEofToken {
163177
this._enableTripleShift = copyFrom._enableTripleShift;
164178
this.tokenStart = copyFrom.tokenStart;
165179
this.groupingStack = copyFrom.groupingStack;

0 commit comments

Comments
 (0)