Skip to content

Conversation

@gvanrossum
Copy link
Collaborator

@gvanrossum gvanrossum commented Mar 26, 2020

Addresses #220 (comment)

Memoization is expensive. In the C generator, we now disable it except for rules with the special marker (memo) after the rule name (and type, if present). By selectively turning on memoization for a handful of rules the parser becomes faster and uses less memory.

Notes:

  • Left-recursive rules always use memoization, since the implementation of left-recursion depends on it.
  • The marker syntax is extensible, in case we need more per-rule flags in the future.

This also adds instrumentation to the C support code to measure how much each rule uses memoization.

Finally, it fixes two lines in scripts/test_parse_directory.py that were still using pegen/ instead of peg_parser/ as the output directory.

@gvanrossum
Copy link
Collaborator Author

This will require precarious porting to the cpython branch at https://github.com/we-like-parsers/cpython :-(

Copy link
Member

@lysnikolaou lysnikolaou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a very small nit, but I think I'd prefer to not have whitespace between the type and the flags. Looks great otherwise!

@gvanrossum
Copy link
Collaborator Author

I think I'd prefer to not have whitespace between the type and the flags.

Hm, I added that intentionally so the flags stand out a bit more -- it's a bit busy already with the type in square brackets.

I'll just land, so we can find out the consequences for other work soon.

@gvanrossum gvanrossum merged commit 54d84ad into master Mar 26, 2020
@gvanrossum gvanrossum deleted the nomemo branch March 26, 2020 15:03
gvanrossum added a commit to we-like-parsers/cpython that referenced this pull request Mar 27, 2020
This is a straightforward port of we-like-parsers/pegen_experiments#236 .

In addition, slightly touched up .gitignore, Makefile (black), mypy.ini.
gvanrossum added a commit to we-like-parsers/cpython that referenced this pull request Mar 27, 2020
This is a straightforward port of we-like-parsers/pegen_experiments#236 .

In addition, slightly touched up .gitignore, Makefile (black), mypy.ini.
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

Successfully merging this pull request may close these issues.

3 participants