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

Make parsing faster #629

Open
bocchino opened this issue Feb 24, 2025 · 3 comments
Open

Make parsing faster #629

bocchino opened this issue Feb 24, 2025 · 3 comments

Comments

@bocchino
Copy link
Collaborator

bocchino commented Feb 24, 2025

The parser combinator library that we use for FPP is easy to use and maintain, but the parsing is inefficient. We could speed up the F Prime build process by implementing an efficient parser.

Unfortunately there is no obvious choice for a faster parser:

  1. There is a Scala parser combinator library called FastParse that is supposed to be fast, but it does not seem to have all the features we need.
  2. The ANTLR parser generator is fast and powerful, but it doesn't support Scala in a clean way, at least as of v4.
  3. We could write our own parser. This is the approach that most production languages take. It would provide complete control over the behavior and performance of the parser. However, it would take some effort.
@Kronos3
Copy link
Collaborator

Kronos3 commented Feb 25, 2025

FWIW VSCode FPP uses ANTLR in a worker thread and posts a JSON version of the AST to the main process. This seems to be quite fast.

It might be possible to use this ANTLR definition and generate Java code. Then post the Java code to our Scala context. It does mean two languages though...

@Kronos3
Copy link
Collaborator

Kronos3 commented Feb 25, 2025

I also wonder if the real slowdown comes from the lexer rather than the parser. The parser's task is quite simple but the lexer needs to try to iteratively match regex together. There might be some better methods for lexing that is faster. Flex for example, does codegen from all the token rules into a character-by-character lexing state machine which seems to be quite fast.

@matt-polo
Copy link

matt-polo commented Feb 25, 2025

Based on this link one can profile scala code with the VisualVM profiler. Note last comment:

I've got same problem, but it can be easily solved by clicking "Settings" checkbox on Profiler page and configuring target and ignored classes properly. In my case a java.* ignore rule blocked profileing of underlying Scala code - Basilevs Commented Sep 7, 2011 at 2:54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

3 participants