How to optimize high-order harmonic generation in gases