Germany solved this by past 4 years of primary school having three different advanced schools that prepare for different types of careers and that have different durations. That's in addition to having AP classes towards the end. It has the downside that it disadvantages late developing children, but there are also ways to continue at the higher schools if you do really well. Making the jump is harder though.
I think this is a decent trade-off between going slower for some kids and holding others back who could go faster and more advanced.