Conversation
Member
Author
|
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).
33862cd to
bad2fe9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).