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

Rewrite symbol pruning. #269

Merged
merged 1 commit into from Nov 19, 2018

Conversation

@dvander
Copy link
Member

dvander commented Nov 18, 2018

reduce_referrers tries to find unused symbols. During parsing, a simple
dependency tree is built, and this leads to a fixpoint algorithm
determining which symbols are transitively unused. Unfortunately, this
algorithm is ridiculously inefficient: it scans all global symbols
during each "sweep", and while processing each symbol, scans all global
symbols again if unused. Due to other considerations the algorithm is
essentially O(nnm).

This patch replaces it with a more efficient solution. This extends the
dependency graph to include backward and forward links, which means
reduce_referrers can use a simple topological sort. The new runtime is
closer to O(n). This is about a 10% improvement in compilation time.

The tricky aspect to this patch is that "symbol" is not pool-allocated
as it would be in normal compilers. And because of Pawn's weird
multi-pass parsing process, symbols are deleted, and we need to make
sure graph links are updated. The previous code took great care to do
this, and additionally to ensure that no duplicate links were added.
However, it is simpler (and faster) to just always add duplicate links,
and to clear all links in between passes (they will be rebuilt anyway).

@dvander

This comment has been minimized.

Copy link
Member Author

dvander commented Nov 18, 2018

Note: I tested this by comparing the dead symbol list before and after on SM plugins. The "before" list has many duplicates, because the algorithm runs way too many iterations. The "after" list has the exact same symbols, but only visits each symbol once.

reduce_referrers tries to find unused symbols. During parsing, a simple
dependency tree is built, and this leads to a fixpoint algorithm
determining which symbols are transitively unused. Unfortunately, this
algorithm is ridiculously inefficient: it scans all global symbols
during each "sweep", and while processing each symbol, scans all global
symbols again if unused. Due to other considerations the algorithm is
essentially O(n*n*m).

This patch replaces it with a more efficient solution. This extends the
dependency graph to include backward and forward links, which means
reduce_referrers can use a simple topological sort. The new runtime is
closer to O(n). This is about a 10% improvement in compilation time.

The tricky aspect to this patch is that "symbol" is not pool-allocated
as it would be in normal compilers. And because of Pawn's weird
multi-pass parsing process, symbols are deleted, and we need to make
sure graph links are updated. The previous code took great care to do
this, and additionally to ensure that no duplicate links were added.
However, it is simpler (and faster) to just always add duplicate links,
and to clear all links in between passes (they will be rebuilt anyway).
@dvander dvander force-pushed the split-headers-p2 branch from 33862cd to bad2fe9 Nov 18, 2018
@dvander dvander merged commit d3ca2ee into master Nov 19, 2018
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@dvander dvander deleted the split-headers-p2 branch Nov 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.