Bacterial swarming is a rapid mass-migration, in which thousands of cells spread collectively to colonize surfaces. Physically, swarming is a natural example for active particles that use energy to generate motion. Accordingly, understanding the constraints physics imposes on these dynamics is essential for understanding the mechanisms underlying swarming. We present new experiments of swarming Bacillus subtilis mutants with different aspect ratios and at different densities; two physical quantities known to be associated with collective behavior. Analyzing the dynamics reveals a rich phase diagram of qualitatively distinct swarming regimes, describing how cell shape and population density govern the dynamical characteristics of the swarm. In particular, we show that under standard conditions, bacteria inhabit a region of phase space that is associated with rapid mixing and robust dynamics, with homogeneous density and no preferred direction of motion. The results suggest that bacteria have adapted their physical properties to optimize the principle functions assumed for swarming.