Ever since upgrading my Mid-2010 MacBook Pro to Lion a few months ago, it sometimes gets extremely sluggish. When it does, every time I switch applications I see something like this in the menu bar:

It stays like that for 10-20 seconds while the system is unresponsive. The mouse is a beachball when I hover over the menu bar. Then the application name appears and the application becomes useable again (but still slow, like everything else). Logging out and in makes the whole issue go away, at least for a while.
What could be causing this?