  Coherent wide parameter-space searches for continuous gravitational waves are
typically limited in sensitivity by their prohibitive computing cost. Therefore
semi-coherent methods (such as StackSlide) can often achieve a better
sensitivity. We develop an analytical method for finding optimal StackSlide
parameters at fixed computing cost under ideal conditions of gapless data with
Gaussian stationary noise. This solution separates two regimes: an unbounded
regime, where it is always optimal to use all the data, and a bounded regime
with a finite optimal observation time. Our analysis of the sensitivity scaling
reveals that both the fine- and coarse-grid mismatches contribute equally to
the average StackSlide mismatch, an effect that had been overlooked in previous
studies. We discuss various practical examples for the application of this
optimization framework, illustrating the potential gains in sensitivity
compared to previous searches.
