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

Restructure ACTION and GOTO tables. #194

Merged
merged 4 commits into from
Oct 2, 2024

Conversation

reventlov
Copy link
Collaborator

@reventlov reventlov commented Sep 27, 2024

With this change, the Parser.action and .goto tables are now 2-layer hash tables, using states as the keys for the outer tables and symbols as the keys for the inner tables. Functionally, this means that action[state, symbol] becomes action[state][symbol], and likewise for goto.

This also allows the expected table to be eliminated, as it can be quickly computed from action[state] when needed.

This goal of this change is to have a more compact representation for issue #193: by structuring the tables this way, state numbers do not need to be repeated in the serialized output. Eliminating expected also provides a modest savings. The total savings is approximately 55%, going from 4.3MB without this change to 1.9MB with this change.

reventlov and others added 3 commits September 27, 2024 18:28
With this change, the `Parser.action` and `.goto` tables are now 2-layer
hash tables, using states as the keys for the outer tables and symbols
as the keys for the inner tables.  Functionally, this means that
`action[state, symbol]` becomes `action[state][symbol]`, and likewise
for `goto`.

This also allows the `expected` table to be eliminated, as it can be
quickly computed from `action[state]` when needed.
if new_action:
if (i, terminal) in action and action[i, terminal] != new_action:
action.setdefault(i, {})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe using defaultdict throughout would be a little simpler. In this case it seems like action could just be a fixed size list of len(item_sets). It kind of depends if we expected an entry for every value of i or if it's sparsely populated. Either way this could be a further improvement, this looks good as-is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done. I'm not sure why I didn't do that in the first place.

@reventlov reventlov merged commit 886cfbb into google:master Oct 2, 2024
4 checks passed
@reventlov reventlov deleted the parser_table_restructure branch October 10, 2024 18:41
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