Skip to content

perf(FragmentsModels): yield tile generation only after a time budget - #317

Open
rihokirss wants to merge 1 commit into
ThatOpen:mainfrom
rihokirss:perf/tile-generation-yield-budget
Open

rihokirss wants to merge 1 commit into
ThatOpen:mainfrom
rihokirss:perf/tile-generation-yield-budget

Conversation

@rihokirss

Copy link
Copy Markdown
Contributor

VirtualTilesController.generate yields the thread with setTimeout(0) every sampleAmount / 20 samples, so progress and ABORT_MODEL messages get through during a load. That is about twenty timers per model, whatever its size. Browsers clamp nested timers to at least 4 ms once they are nested more than five levels deep (each yield is set from the continuation of the previous one), so every load waits roughly 60–80 ms even when generating its tiles takes a millisecond.

The editor pays this on every geometry edit: EditHelper.edit loads a new delta model (load → _setup → CREATE_MODEL → setupData → generate), usually a model of a few items.

Change

  • Yield at the first step, as before, so a load can still be aborted before it generates. A single-threaded model starts loading in its constructor and can be disposed right after it (single-threading/index.test.ts covers that). A first timer is not clamped.
  • After that, yield only once 16 ms of work have passed since the last yield.
  • Progress is still reported and throwIfAborted is still checked at every step, so large models keep yielding regularly and aborts land at the same steps.

Measurements

An app that draws cable trays with the editor on a federated project, headless Chromium, the same machine before and after. Four models were loaded (about 3 M triangles); the edited model has 176 items and roughly 120 unsaved requests per drawn segment. Each step is one render-affecting edit() plus one data-only edit().

per drawn segment before after
delta model _setup 100–140 ms 37–50 ms
both edit() calls 145–176 ms 66–87 ms

Initial loads of ordinary models save the same fixed 60–80 ms each.

Tests

virtual-tiles-yield.test.ts loads school_arq.frag through VirtualFragmentsModel.setupData:

  • With time frozen, generation uses one timer (21 before this change), while progress and abort checks still run at every step.
  • With every step slower than the budget, it yields at every step and an abort still interrupts the load.

The full packages/fragments suite passes (145 tests).

VirtualTilesController.generate yielded the thread with setTimeout(0)
about twenty times per model so progress and ABORT_MODEL messages get
through. Browsers clamp nested timers to 4 ms, so every load waited
60-80 ms even when generating took a millisecond. The editor pays this
on every geometry edit, because each edit loads a new delta model.

Yield once at the first step (so a load can still be aborted before it
generates, e.g. a single-threaded model disposed right after its
constructor; a first timer is not clamped) and then only after 16 ms of
work. Progress is still reported and aborts are still checked at every
step.

Measured in an app that continues a cable route on a federated project
(4 models, ~1300 unsaved requests): delta model setup went from
100-140 ms to 37-50 ms per edit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant