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.
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).