density spare optimization code update