Better app restart required logic

Any assumption on the original state of the functions concerned is
almost certainly false in a fair number of common situations.

Solution: record the state of the concerned functions before
modifying, and compare with the state after modification
Check restart needed for apps on import as they are finished
Fix restart checks for import
Cache the list of methods requiring restart for performance
Cleanups
Merge pull request #1236 from jpeg729/rebased_restart

Rebased restart logic rewrite