You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
we rely heavily on between, which is based on sequence and bind. If we would find the tiniest speed improvement in those, we would make the parser a lot faster.
we rely on this function often in the JSON parser too. It is built in terms of sepBy1 which is written in a "readable" way, but not a really efficient way:
The prepend uses array_merge to prepend a single element, could probably be faster with array_unshift
although the applicative is really readable here, it's also a complex operation under the hood, and like the sequence and bind the tiniest improvement here would probably make a big difference
We use zeroOrMore in combination with choice, which is a slow process of trying parsers and moving on to the next one. Maybe we can make this faster with the takeWhile stream method or something like it.
related: parsica-php#17
inspired by this regex:
```
/^
"[^"\\]* # double quoted strings with possibly escaped double quotes
(?:
\\. # escaped character (quote)
[^"\\]* # unrolled loop following Jeffrey E.F. Friedl
)*
"
/x
```
i implemented an unrolled loop in combination with takeWhile. (the last use of the deprecated zeroOrMore was also removed)
this leads to a big performance boost from ca ~250%(without xdebug) - ~330%(with xdebug) - both without opcache.
before:
bench_json_encode: 4.133μs
bench_Parsica_JSON: **4.109ms**
bench_basemax_jpophp: 432.128μs
after:
bench_json_encode: 3.744μs
bench_Parsica_JSON: **1.662ms**
bench_basemax_jpophp: 401.154μs
1. whitespace parser
it's potentially faster to do takeWhile on the stream, with the same predicate, skipping the
zeroOrMore
combinator and thesatisfy
.https://github.com/mathiasverraes/parsica/blob/main/src/JSON/JSON.php#L154-L158
2. between
we rely heavily on
between
, which is based onsequence
andbind
. If we would find the tiniest speed improvement in those, we would make the parser a lot faster.https://github.com/mathiasverraes/parsica/blob/main/src/JSON/JSON.php#L96-L103
3. sepby
we rely on this function often in the JSON parser too. It is built in terms of
sepBy1
which is written in a "readable" way, but not a really efficient way:array_merge
to prepend a single element, could probably be faster witharray_unshift
sequence
andbind
the tiniest improvement here would probably make a big differencehttps://github.com/mathiasverraes/parsica/blob/main/src/JSON/JSON.php#L99-L102
https://github.com/mathiasverraes/parsica/blob/main/src/combinators.php#L513-L519
The text was updated successfully, but these errors were encountered: