Skip to content

perf(saved-graphics): saved graphics are read and meshed 10-24% faster with byte-identical output #881

Closed

Description

@n3ur0m4n

Problem

Reading saved graphics (rvt-gltf --saved-meshes, rvt-ifc --saved-meshes, native_saved_scene) spends much of its time on work that can be skipped or shared, without changing what is written:

  • PointerIndex::new rebuilds the edge and token tables of an object graph every time it is called, and the free native_saved_mesh::pointer() scans every edge and every object of the graph for each pointer it resolves.
  • The saved-scene passes call native_document::extract, which first makes the parameter-definition pass over every definition owner; the saved scene never reads parameter values.
  • Elements are meshed one after the other, although each element's meshing is independent.
  • Freeing the decoded graphs at the end takes noticeable time on large models.

Proposed solution

Cache the pointer lookup tables on ObjectGraph, read the saved-scene passes with extract_graphs, mesh elements in parallel keeping document order, and drop the decoded graphs on a background thread.

Measured on the redistributable reference models (tools/fetch-reference-models.sh), median of 5 runs of rvt-gltf <file> --saved-meshes, release build, Windows 11, 24 logical cores, idle machine:

model size before after gain
2024_Core_Interior.rvt 33.7 MB 5.49 s 4.93 s 10%
RE1-Architecture.rvt 6.6 MB 1.29 s 0.98 s 24%
RE1-Electrical.rvt 13.4 MB 2.01 s 1.53 s 24%
RE1-Mechanical.rvt 3.4 MB 1.09 s 0.83 s 23%
RE1-Plumbing.rvt 3.5 MB 0.88 s 0.70 s 21%
Revit_IFC5_Einhoven.rvt 0.9 MB 0.23 s 0.20 s 13%

Reading a model's full saved scene (extract_at_detail at detail 3 with no selection, as a viewer would, and writing it as JSON) gains more: 2024_Core_Interior 9.35 s to 7.15 s (24%), RE1-Architecture 1.01 s to 0.60 s (40%), RE1-Electrical 1.19 s to 0.89 s (26%), RE1-Mechanical 0.75 s to 0.54 s (28%), RE1-Plumbing 0.66 s to 0.50 s (25%).

The .glb written is byte-identical before and after on all six models and the three tier1 fixtures. tools/bench.sh does not run any command that reads saved graphics, so it shows no change; the table above is the before/after for this path. A pull request follows.

Alternatives considered

Keeping native_document::extract in the saved-scene passes keeps the summaries unchanged (see below) but pays for the parameter-definition pass on every read.

Affected subsystem

Element decoders

Breaking change

Yes

native_saved_scene::SavedScene::summaries would no longer carry parameter_definitions, unit_formats and parameter_binding_context, because the passes use extract_graphs. The scene's elements are identical, and nothing in the crate reads those fields from a saved scene.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions