Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tricks for >5x performance increase #151

Open
fy0 opened this issue May 16, 2024 · 0 comments
Open

Tricks for >5x performance increase #151

fy0 opened this issue May 16, 2024 · 0 comments

Comments

@fy0
Copy link

fy0 commented May 16, 2024

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. But basicLatinChars [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 and popV and parser.vstack, use p.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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant