Cache string length to improve performance