This question is a complex one. It has several facets. One trade off that is obvious is velocity vs. accuracy or group size.
That has been mentioned above. Weight is another that has been mentioned.
LINK:
This link just above is to varmintal and the author of this website is a retired physicist from Lawrence Livermore Labs. His name is Al Harral.
He spent his career using finite element analysis models to model explosions and structural reactions. These models divide the structure, in this case a rifle into tiny little cells or blocks and model the the explosions and the pressure and sound, and physics from one cell to the next
cell by cell until the bullet leaves the muzzle.
He modeled a 6 mm rifle in 20, 22, 24 inch with tuners and all the specifics of the bbl. measurements, taper, etc. are listed about half way down on the link page. He found the 24 inch gave the best grouping. He also plotted all the data from an experiment that Richard Lomax did and wrote about where he progressively cut an inch at a time from a .223 bbl. and measured accuracy or grouping. He found the optimum bbl.
length was about 17 inches in that experiment. All the data is presented towards the bottom of this linked page.
Harral shows that
the results will matter depending on what powder and burn rate and bullet size is used in a particular rifle.
That just makes sense, and all of this is also tied to barrel harmonics and as we know length, weight, and taper all affect barrel harmonics
and accuracy.
But I think I can generalize just this much.......for a regular hunting rifle of avg. weight, barrel taper, etc. with a scope mounted on it,
likely the best accuracy will be in the 22-24 inch range. One might get slightly better accuracy with a 17 inch barrel, but at the sacrifice of velocity and range. Ie, 100 yard rifle accuracy if that's the goal.
Likely, when one starts shooting magnum calibers with barrels longer than 22-24 inches, one may lose some accuracy due to barrel harmonics.
again assuming avg. barrel taper and weight, all other things being equal. In a magnum caliber with longer barrels, extra barrel diameter, and
and weight would be desireable to compensate for harmonics in order to retain accuracy.
That's a generalization but one that I believe is in the correct direction.