-
Notifications
You must be signed in to change notification settings - Fork 68
Open
Description
These tricks based on tests of parser generated by pointlander/peg and pigeon with same grammer on my computer (12600kf, win11). baseline is pointlander/peg(~0.3s). First version of pigeon with same grammar took 4.5s.
- Never use state, extermely slow. (-2.2s for not use state, -0.9s for disable state by option).
- Remove
vals := make([]any, 0, len(seq.exprs))
from parseSeqExpr or just collect !nil values (-0.55s) - Don't enable
-optimize-basic-latin
, it seems not improved. ButbasicLatinChars [128]bool
is always a part of charClassMatcher, remove it. (-0.06s) - Map access of
ruleRefExpr
takes ~0.2s, replace it by index take ~0.05s. (-0.15s) - Reduce the use of label syntax, especially in situations where your label matched but then the sentence match fails, leading to another path to match(backtracking). A few label without backtracking is fast.
- Remove
pushV
andpopV
and parser.vstack, usep.vstack = make(map[string]any)
to instead. (-0.06s, it seems took long time(~50%) in cpu profiler, but i did't got so much performance improved by remove it.) parser.rstack
takes ~0.02s. (i didn't remove it)
Finally, we can got a parser cost 2x times by a parser generated by pointlander/peg. My current version take 0.5s to pass test, it's a huge boost compare to original version(4.5s), but still much slower than pointlander/peg.
It's a ok trade off for me, because code generated by pigeon is more simple and clear. And easy to port builder to other languages.
If anyone know how to make it faster, please tell me.
- On linux(github action, i did't test on a real linux env), pointlander/peg is much faster. Even the optimized verison of pigeon, cost 4x when cold start, 10x when warn start.
elireisman and skowrons
Metadata
Metadata
Assignees
Labels
No labels