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

Improve Lookahead functions and maxLookahead handling #1012

Closed
1 task done
bd82 opened this issue Aug 26, 2019 · 1 comment
Closed
1 task done

Improve Lookahead functions and maxLookahead handling #1012

bd82 opened this issue Aug 26, 2019 · 1 comment

Comments

@bd82
Copy link
Member

bd82 commented Aug 26, 2019

Changes

  • Moved Lookahead Function computation to parser initialization.
    - This Increases the initialization time, but gained 5-15% runtime performance boost (Parser only benchmark, no Lexer involved).
  • Support maxLookahead config per DSL method rather than just a global setting.
    class LowLookaheadParser extends CstParser {
        constructor() {
            super([], {
                // Globally **only one** token lookahead.
                maxLookahead: 1
            })
    
            $.RULE("value", () => {
                $.OR({
                    // We need **two** tokens lookahead to distinguish between these two alternatives
                    MAX_LOOKAHEAD: 2,
                    DEF: [
                        {
                            ALT: () => {
                                $.CONSUME(A)
                                $.CONSUME(B)
                            }
                        },
                        {
                            ALT: () => {
                                $.CONSUME(A)
                                $.CONSUME(C)
                            }
                        }
                    ]
                })
            })
    
            this.performSelfAnalysis()
        }
    }

Original Issue

The LA functions are evaluated lazily when needed.
This is useful when parsing small inputs that may not need all of the LA functions.

However if by creating these all LA functions at startup it may be possible to:

  • Improve runtime speed by avoiding the check if the LA function has been created.
  • Improve analysis speed by memoization of previous results.
  • Enable inspecting the actually needed maxLookahead versus the one defined by the user.
  • Enable providing these lookahead functions "pre-prepared" e.g via some kind of code generation. this could both:
    • Reduce init/first run time.
    • Increase runtime performance by providing more optimized lookahead functions
@bd82
Copy link
Member Author

bd82 commented Aug 30, 2019

WIP here: #1022

@bd82 bd82 changed the title Move Lookahead Functions creation to the initialization phase Improve Lookahead functions handling Sep 2, 2019
@bd82 bd82 changed the title Improve Lookahead functions handling Improve Lookahead functions and maxLookahead handling Sep 2, 2019
@bd82 bd82 closed this as completed Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant