Commit 148ceff
Lexer: extract the matches with PREG_PATTERN_ORDER
PREG_SET_ORDER allocates one array per match. Now that the token patterns
have no capturing groups those arrays hold two entries each -- the whole
match and the MARK -- and tokenize() reads both out and drops the array
again, so lexing pays one array allocation per token for nothing.
PREG_PATTERN_ORDER collects the whole PHPDoc into two arrays instead:
$matches[0] holds the values and $matches['MARK'] the token types. Two array
headers per PHPDoc rather than one per token.
Measured over 37150 unique docblocks (8.38 MiB, 2.36M tokens) collected from
20 OSS libraries, one full vendor tree, phpstan-src and this library:
lexing parse (lex + PhpDocParser)
PHP 8.1 -42%
PHP 8.4 -40%
PHP 8.5 -40% -19%
tokenize() still returns list<array{string, int, int}>, and both the tokens
and the ASTs printed from them are byte-identical to before over the whole
corpus.1 parent e59b0c8 commit 148ceff
1 file changed
Lines changed: 16 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
| |||
116 | 115 | | |
117 | 116 | | |
118 | 117 | | |
119 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
120 | 130 | | |
121 | 131 | | |
122 | 132 | | |
123 | | - | |
124 | | - | |
125 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
126 | 136 | | |
127 | 137 | | |
128 | 138 | | |
| |||
137 | 147 | | |
138 | 148 | | |
139 | 149 | | |
| 150 | + | |
140 | 151 | | |
141 | 152 | | |
142 | 153 | | |
| |||
0 commit comments