The nodes of Ranvier (the gaps between myelin sheath segments) speed up the action potential because the electric current can jump from node to node (or gap to gap). If the myelin covered the entire axon, the signal wouldn't have the gaps to speed up the signal. As for optimal length, the gap is 1μm long, but can be longer, on the order of millimeters depending on the type of cell. The length of the myelin doesn't matter so much as the length of the nodes of Ranvier because they are where the Na+/K+ channels are found so the ion exchange can occur. This is how an action potetial can occur, so the myelin not covering the entire axon is crucial for the ability of neurons to propagate a signal.