Open turanct opened 3 years ago
Another improvement would be the string parser:
It's faster to parse a bunch of nested objects, than it is to parse a list of simple strings.
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.
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