message: gaussian density, avoid large async function
diff: @@ -24,10 +24,6 @@ export async function GaussianDensityCPU(ctx: RuntimeContext, position: Position
  const r = radius(OrderedSet.getAt(indices, i)) + radiusOffset
  if (maxRadius < r) maxRadius = r
  radii[i] = r
  -
  - if (i % 100000 === 0 && ctx.shouldUpdate) {
  - await ctx.update({ message: 'calculating max radius', current: i, max: n })
  - }
  }
  const pad = maxRadius * 2 + resolution
  @@ -54,10 +50,10 @@ export async function GaussianDensityCPU(ctx: RuntimeContext, position: Position
  const densData = space.create()
  const alpha = smoothness
  - const updateChunk = Math.ceil(1000000 / (Math.pow(maxRadius * 2, 3) * resolution))
  + const updateChunk = Math.ceil(100000 / ((Math.pow(Math.pow(maxRadius, 3), 3) * scaleFactor)))
  - console.time('gaussian density cpu')
  - for (let i = 0; i < n; ++i) {
  + function accumulateRange(begI: number, endI: number) {
  + for (let i = begI; i < endI; ++i) {
  const j = OrderedSet.getAt(indices, i)
  const vx = x[j], vy = y[j], vz = z[j]
  @@ -110,12 +106,22 @@ export async function GaussianDensityCPU(ctx: RuntimeContext, position: Position
  }
  }
  }
  + }
  + }
  +
  + async function accumulate() {
  + for (let i = 0; i < n; i += updateChunk) {
  + accumulateRange(i, Math.min(i + updateChunk, n))
  - if (i % updateChunk === 0 && ctx.shouldUpdate) {
  + if (ctx.shouldUpdate) {
  await ctx.update({ message: 'filling density grid', current: i, max: n })
  }
  }
  - console.timeEnd('gaussian density cpu')
  + }
  +
  + // console.time('gaussian density cpu')
  + await accumulate()
  + // console.timeEnd('gaussian density cpu')
  const transform = Mat4.identity()
  Mat4.fromScaling(transform, Vec3.create(resolution, resolution, resolution))
  