heap cost calculation improvement