Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Rewrite symbol pruning. #269
reduce_referrers tries to find unused symbols. During parsing, a simple
This patch replaces it with a more efficient solution. This extends the
The tricky aspect to this patch is that "symbol" is not pool-allocated
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).