Everything is a compromise. Most published ballistics you see for handguns are from 8" barrrels. With that length, or close to it, you'll come close. Going longer and you might do better.
Going shorter will effect performance. Most rifles are tested with 24" barrels and folks understand very well that they lose performance with shorter barrels. Most would never consider anything shorter than 18-20" on a rifle. Yet they are surprised when they find that a magnum handgun round from a 2"-4" barrel is far slower than expected. A handgun barrel that short is about like shooting a 300 magnum rifle with a 6"-12" barrel.
My personal thoughts are that a magnum handgun round needs a minimum or 4" or you are wasting your time. I also don't want to carry anything longer than 6". If I need anything longer I'll carry a rifle for real performance.