Popup: Performance improvements. Fixes #5958. Found with git bisect.