I own quite a few 22 rifles with barrels from 18.5 to 25" and have chronographed them all using several different brands of ammo. Of course the longer the barrel, the higher the velocity. My old Remington 511 has a 25" barrel and will shoot sub-MOA groups at 100 yds. I have a 25" CZ that is the most accurate out-of-the-box 22 I've ever seen. 1/4" groups @ 100 yds with CCI Minimags.
A friend gave me an old Marlin mod 10. It is a single shot bolt gun that came with a 24" barrel. The stock and receiver were in good shape but the barrel was trashed. I replaced it with a new "take off" Ruger 10/22 barrel (18.5") that I bought at a gun show for $10. Even though the 10/22's aren't known for fine accuracy, this barrel really impressed me when installed in the old rifle. I scoped the gun and can easily get 1" groups @ 100 yds (Federal match ammo). The MV suffers so I have to allow for an inch or so more drop. Point is, the longer barrels will probably be more accurate but if a 18.5" Ruger barrel can do an inch group, a quality barrel should be even better.
I really don't think there is any magic optimum length for a 22. So much depends on the bore, chamber, crown and rifling, in addition to the ammo. One thing is for sure, you will loose MV with a shorter barrel.