perf($compile): only iterate over elements with link functions

Closes #8741