optimize memory occupation computation