optimize the size calculation