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

Use cache for recursion in grammar.py to avoid unnecessary retraversal. #162

Merged
merged 2 commits into from
Aug 4, 2022

Conversation

Silver-Golden
Copy link

I threw a large bnf at scripts/GE_LR_parser.py and it failed to complete in a timely manner (8 hours and counting).
I investigated a tad and found that it was seemly stalling on the check_recursion subfunction.

In its preexisting form it did not check if a node/symbol had been traversed, opting to traverse it every time it was encountered.
(I also took a look at teh depth and found it was "stuck" around layer 120+, considering that I am not sure if the original implementation would finish my bnf in my lifetime)

Adding a cache to store and fetch a symbols result allows for each subtree to be traversed only once.
Runtime is near instant now.

@jmmcd
Copy link
Collaborator

jmmcd commented Aug 4, 2022

Looks good, thanks!

@jmmcd jmmcd merged commit 8ee2bd1 into PonyGE:master Aug 4, 2022
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.

2 participants