parserz icon indicating copy to clipboard operation
parserz copied to clipboard

Experiment - do not pass state and input between steps

Open sergei-shabanau opened this issue 4 years ago • 0 comments

⚠️ Interesting code here:

  • final def parser[S, E, A] function in ParserModule2
  • InOut.scala
  • changes to the test.

The rest is a copy-paste of existing code, please ignore it. ⚠️

Trying the following:

  • consuming from Array[Char]
  • thus not having interim Input created
  • using mutable state instead of passing and returning state at every step

The parser signature currently is (ignore the S parameter):

final def parser[S, E, A](grammar: Grammar[S, S, E, A]): Input => E \/ A

I tested the code in the perf test for parsing JSON that I use as a base line to compare with FastParse.

I have an improvement over previous design: 1,000,000 runs in ~15 sec vs ~25 sec as before. This is not great as FastParse does it in ~4 sec 😐

What do I have extra compared to FastParse?

  • Either returned at ever step
  • traversal of grammar during execution
  • recursive and polymorphic step function call

From what I found while working on this part, polymorphic functions did the the biggest contribution to lower performance.

sergei-shabanau avatar Apr 02 '20 15:04 sergei-shabanau