linksync.py: optimization

Lots of messages are being frozen and thawed even though they needn't
be changed. Skip such messages.
linksync.py: wrap main body in a function

This makes it easier to profile.