Calculate size outside foreach