it turns out that there was no bug in density computation with grid optimization. the problem was that particles were assigned to grid cells nad the accumulation of density iterates over those cells, therefore losing the original particle order. due to limited float accuracy, different ordering of particles resulted in slighlty different results of addition. the error accumulated in consecutive time steps - that's why i saw in only in the later time steps. so, in the end, i did not have to worry about it...