Optimize unused dependency checking.