It is close to optimal for data compression (see Source coding theorem), but it isn't optimal.
See Shannon-Fano-Elias code and simplicity bias in GP maps