You don’t realize how much switching jobs sucks until you do it. I moved on from my first post-college jobs after almost 4 year, and its been more of a shock than I expected. Once you have been working at a company for a few years you start to know everything that is going on. You know how to be productive. You know who is important, what projects are important and have a good idea of where things are going. You know if your job is secure and how to do well. But once you switch jobs, all that goes out the window and you have to start building up your organizational knowledge again.
The best way to increase your compensation is to switch jobs every 2-3 years. But while that saying is correct it underplays the cost to you of switching jobs. Yes, you are getting paid more. But you gave up your political position in your last company. You lost years of domain expertise and a large number of valuable relationships. If you left on good terms, which everyone should, you will still have those people in your network. But they will not be in your corner for the next political battle.
Early in your career switching regularly is probably the best option. But as you move up in the hierarchy you may need to stay at companies for longer terms. At the beginning you can get promoted every years, Developer 1, Developer 2, etc. But you reach a point eventually where it takes longer to move up. Going from engineering manager to vice president is much harder to do than moving from senior engineer to engineering manager. You will need to know more people and have a better political position to reach vice president than engineering manger.