Messagestack size function optimization

Count the array only if is not empty