Skip to content

saved_meshes::attach on 0.14: owner graphs are the peak holder (request for a 0.14-compatible fix) #1808

Closed

Description

@shifatrHtH

Context

We consume rvt = "=0.14.0" behind an adapter and compare the decoded artifact exactly: tiles, element rows, properties, pixels, picks, and lifecycle. We cannot take the 0.18/0.19 default saved-mesh scope and exported-property changes as a performance-only bump. We are asking for a 0.14-compatible reader release, or a bounded/streaming saved_meshes::attach.

Measurements

Direct worker --stage pipeline, macOS arm64, 48 GiB host. Three fixtures:

Fixture Saved-attach candidates 0.14.0 batch 128 0.14.0 unbatched
122 MiB Revit 2024 2,820 3.158 GB / 13,980 ms 6.789 GB / 10,330 ms
190 MiB 756 1.634 GB / 8,990 ms 1.659 GB / 7,840 ms
385 MiB 1,114 3.202 GB / 14,450 ms 3.310 GB / 10,130 ms

The outer batching is ours; it trades wall for peak because the reader retains owner graphs.

0.14 owner-graph spike

We ported the 0.18 owner-graph retention path (#1690/#1691) to a scratch 0.14 copy: owners that name nothing are read again and meshed a buffer at a time; meshed owner graphs are released; owners another owner names are kept.

Fixture Baseline 0.14 + owner-graph path Artifact
122 MiB, batch 128 3.158 GB / 13,980 ms 1.916 GB / 15,250 ms identical
122 MiB, unbatched 6.789 GB / 10,330 ms 1.825 GB / 11,300 ms identical
190 MiB, unbatched 1.659 GB / 7,840 ms 1.654 GB / 7,920 ms identical
385 MiB, unbatched 3.310 GB / 10,130 ms 3.317 GB / 10,160 ms identical

Run unbatched, the 122 MiB fixture is 1.825 GB / 11,300 ms against our current 0.14 batch-128 path of 3.158 GB / 13,980 ms: lower peak and faster, identical artifact. This is the both-metrics lever.

#1701 alone is not enough

A scratch 0.14 copy with only #1701's planner, unbatched on the 122 MiB fixture, moved peak 6.789 → 6.699 GB (−1.8%) and wall 10,330 → 11,420 ms (+10.0%). The extra body-size walk costs more than the plan saves. #1701 is optional for us; the owner graphs are the holder.

Ask

  1. Primary: a 0.14-compatible patch release with the owner-graph retention path (Default saved meshes: peak memory is 1.4 to 4.4 times 0.17.0's on Revit 2023 to 2027 files, where #1191 measured up to 1.6 #1690/fix(research): the saved-mesh pass reads each owner's graph with the batch it is meshed in, so the default export no longer holds every wall's graph at once (#1690) #1691), or a bounded/streaming saved_meshes::attach that caps retained saved geometry without changing the artifact.
  2. Fallback: a next-release opt-in that preserves 0.14's saved-mesh selection and artifact behavior.

0.19.0's changelog includes the owner-graph work, but its default export moves 107 of 126 measured exports and changes properties/quantities, so it is not a drop-in for an exact-artifact consumer.

0.14 port patch

The measured 216-line port is below; it is a scratch build against v0.14.0, not a request for you to accept this exact code. The 0.18 implementation is the reference.

0.14 owner-graph patch
--- a/src/research/native_saved_scene.rs	2006-07-24 11:21:28
+++ b/src/research/native_saved_scene.rs	2026-11-12 16:01:34
@@ -368,6 +368,36 @@
 /// `control` is its too: [`Stage::SavedGraphics`] at 0 and then at 1 of 1
 /// once the owners are read, then [`Stage::SavedMeshes`] at 0 and once for each
 /// owner meshed, of the number of owners.
+/// The graph objects of the owners that name nothing that are held at once
+/// while they are meshed: the buffer is meshed and let go when it holds this
+/// many (the same 95 MiB or so as a batch of symbols).
+const OWNER_OBJECT_BUDGET: usize = 20_000;
+/// Mesh the owners of `buffer`, give each element to `visit` and let the graphs
+/// go.
+fn mesh_buffer(
+    buffer: &mut BTreeMap<u64, Record>,
+    run: &MeshRun<'_>,
+    visit: &mut impl FnMut(SavedElement) -> Result<()>,
+) -> Result<()> {
+    if buffer.is_empty() {
+        return Ok(());
+    }
+    let ids: Vec<u64> = buffer.keys().copied().collect();
+    let no_shared = BTreeMap::new();
+    let elements = mesh_elements(
+        &ids,
+        Records {
+            owners: &*buffer,
+            shared: &no_shared,
+        },
+        run,
+    )?;
+    for element in elements {
+        visit(element)?;
+    }
+    buffer.clear();
+    Ok(())
+}
 pub fn extract_in_batches_with_control(
     file: &mut RevitFile,
     options: &Options,
@@ -384,25 +414,50 @@
     let mut opts = options.clone();
     opts.channels = BTreeSet::from([103]);
     opts.record_extras = true;
+    // Everything each owner's graph names. An owner can name another owner,
+    // whose own symbols its mesh then reaches, as the one-shot read finds them
+    // by reading every record's references.
+    let mut owner_references = BTreeMap::<u64, Vec<u64>>::new();
     let mut owners = BTreeMap::<u64, Record>::new();
     native_document::extract_graphs(file, &opts, |r| {
+        let id = r.identity.element_id;
+        let references = instance_symbols(&r);
+        let names_something = !references.is_empty();
         ensure!(
-            owners.insert(r.identity.element_id, r).is_none(),
+            owner_references.insert(id, references).is_none(),
             "duplicate current graphics owner"
         );
+        // An owner that names nothing is not kept: its graph is its own
+        // geometry (a wall's is about 1.6 MiB, #1429, and a file has hundreds),
+        // and it is read again below and meshed a buffer of them at a time. One
+        // that names a symbol or an owner is kept, as every owner was, for the
+        // batch that meshes it with what it names.
+        if names_something {
+            owners.insert(id, r);
+        }
         Ok(())
     })?;
-    // Everything each owner's graph names. An owner can name another owner,
-    // whose own symbols its mesh then reaches, as the one-shot read finds them
-    // by reading every record's references.
-    let owner_references: BTreeMap<u64, Vec<u64>> = owners
+    // The owners another owner names: their graphs stay for the mesh of the one
+    // that names them. Every other owner's graph is freed once it is meshed.
+    let named_owners: BTreeSet<u64> = owner_references
+        .values()
+        .flatten()
+        .copied()
+        .filter(|symbol| owner_references.contains_key(symbol))
+        .collect();
+    // The owners that name nothing, and that no owner names: meshed in one
+    // further pass, before the batches.
+    let streamed: BTreeSet<u64> = owner_references
         .iter()
-        .map(|(&id, record)| (id, instance_symbols(record)))
+        .filter(|(id, references)| references.is_empty() && !named_owners.contains(*id))
+        .map(|(&id, _)| id)
         .collect();
-    // Each owner with the symbols it names that are not owners themselves,
-    // ordered so that owners naming the same symbols are next to each other.
+    // Each of the other owners with the symbols it names that are not owners
+    // themselves, ordered so that owners naming the same symbols are next to
+    // each other.
     let mut named: Vec<Named> = owner_references
         .iter()
+        .filter(|(id, _)| !streamed.contains(*id))
         .map(|(&id, references)| {
             let symbols: BTreeSet<u64> = references
                 .iter()
@@ -413,7 +468,7 @@
         })
         .collect();
     named.sort();
-    let total = named.len() as u64;
+    let total = owner_references.len() as u64;
     // The progress is the one-shot read's, whatever the batches: the graphics
     // are reported read once the owners are, and each owner is reported meshed
     // once, in order, against the same total.
@@ -429,6 +484,26 @@
         done: &done,
         total,
     };
+    // The owners that name nothing are read in one pass and meshed a buffer of
+    // about 20,000 graph objects at a time, as they are read.
+    if !streamed.is_empty() {
+        let mut buffer = BTreeMap::<u64, Record>::new();
+        let mut held = 0usize;
+        opts.selected_ids = streamed;
+        native_document::extract_graphs(file, &opts, |r| {
+            held += r.graph.as_ref().map_or(0, |graph| graph.objects.len());
+            ensure!(
+                buffer.insert(r.identity.element_id, r).is_none(),
+                "duplicate current graphics owner"
+            );
+            if held >= OWNER_OBJECT_BUDGET {
+                mesh_buffer(&mut buffer, &run, &mut visit)?;
+                held = 0;
+            }
+            Ok(())
+        })?;
+        mesh_buffer(&mut buffer, &run, &mut visit)?;
+    }
     let mut limit = FIRST_BATCH_SYMBOLS;
     let mut next = 0;
     let mut freeing: Option<std::thread::JoinHandle<()>> = None;
@@ -437,7 +512,10 @@
         let mut ids = Vec::new();
         let mut symbols = BTreeSet::<u64>::new();
         while let Some((_, id, own)) = named.get(next) {
-            if !ids.is_empty() && symbols.union(own).count() > limit {
+            // The owners that name no symbol sort first and make a batch that
+            // reads none, so that their graphs are gone before any symbol is.
+            let ends_symbol_free = symbols.is_empty() && !own.is_empty();
+            if !ids.is_empty() && (ends_symbol_free || symbols.union(own).count() > limit) {
                 break;
             }
             ids.push(*id);
@@ -462,6 +540,25 @@
             &attempted,
             &mut wanted,
         );
+        // An owner the batch's owners name that names nothing was not kept (an
+        // owner that names something was): it is read now, and kept as it is
+        // named. An owner a symbol names is read with the symbols below.
+        let missing: BTreeSet<u64> = expanded
+            .iter()
+            .copied()
+            .filter(|id| !owners.contains_key(id))
+            .collect();
+        if !missing.is_empty() {
+            control.check()?;
+            opts.selected_ids = missing;
+            native_document::extract_graphs(file, &opts, |r| {
+                ensure!(
+                    owners.insert(r.identity.element_id, r).is_none(),
+                    "duplicate current graphics owner"
+                );
+                Ok(())
+            })?;
+        }
         for depth in 0..=128 {
             if wanted.is_empty() {
                 break;
@@ -479,6 +576,14 @@
                 );
                 Ok(())
             })?;
+            // A symbol that names an owner whose graph was freed with an
+            // earlier batch (no owner names it, so it was not kept): the mesh
+            // looks it up among the shared records, so it is read again.
+            wanted.extend(found.iter().copied().filter(|id| {
+                owner_references.contains_key(id)
+                    && !owners.contains_key(id)
+                    && !attempted.contains(id)
+            }));
             add_references(
                 found,
                 &owner_references,
@@ -503,12 +608,25 @@
         for element in elements {
             visit(element)?;
         }
-        limit = (BATCH_OBJECT_BUDGET.saturating_mul(shared.len().max(1)) / objects.max(1))
-            .clamp(MIN_BATCH_SYMBOLS, MAX_BATCH_SYMBOLS);
+        // Only a batch of symbols sizes the next one.
+        if !symbols.is_empty() {
+            limit = (BATCH_OBJECT_BUDGET.saturating_mul(shared.len().max(1)) / objects.max(1))
+                .clamp(MIN_BATCH_SYMBOLS, MAX_BATCH_SYMBOLS);
+        }
+        // The batch's owners are meshed: their graphs go with its symbols,
+        // those another owner names excepted.
+        let meshed: Vec<Record> = ids
+            .iter()
+            .filter(|id| !named_owners.contains(*id))
+            .filter_map(|id| owners.remove(id))
+            .collect();
         // Freeing the decoded graphs takes seconds on large models: do it
         // aside where there are threads.
         if workers() > 1 {
-            freeing = Some(std::thread::spawn(move || drop(shared)));
+            freeing = Some(std::thread::spawn(move || {
+                drop(shared);
+                drop(meshed);
+            }));
         }
     }
     Ok(())

Activity

  1. DrunkOnJava commented on Nov 12, 2026

    @DrunkOnJava
    Owner

    Thanks for the measurements and the port. We'll ship this as 0.14.1, a patch release cut from v0.14.0 that changes nothing but the saved-mesh pass's memory.

    What goes in. Two fixes from main, cherry-picked onto v0.14.0 on branch hotfix/v0.14.1:

    native_saved_scene.rs on the branch then equals 979ec428's, except for #1449's Revit 2015 to 2022 meshing, which 0.14 does not have. Nothing else from 0.15 to 0.19 comes in: not the default saved-mesh scope, not the property changes, not #1701.

    The fallback. An opt-in in a later release that keeps 0.14's selection and output is not planned. It would mean carrying two exporters.

    Rows, registered before any run. Two Measure runs of the branch against v0.14.0, with the branch's own (0.14) workflow and scorers: the samples of every year, the BIM4LCA models, BIMcollab and the held-out models.

    1. Default export unchanged. Every model's ifc.sha256 and every scorer file equal v0.14.0's.
    2. --saved-meshes export unchanged. With every boxed element drawn from its saved mesh, the attach you measure, every model's ifc.sha256 equals v0.14.0's.
    3. Peak, --saved-meshes. No file's peak resident memory is above 1.02 of v0.14.0's. On the BIM4LCA office, as built and at permit, whose walls are owners that name nothing, it falls to 0.80 of v0.14.0's or less. If neither office falls that far, the backport does not do on our files what your port did on yours, and it is read again before any tag.
    4. Time, --saved-meshes. The median over the samples of Revit 2023 to 2027 is at most 1.10 of v0.14.0's, and no file is above 1.25. The owners that name nothing are read twice, so some cost is expected. Your port measured +9% on the file where it saved the most.

    The branch also runs the full CI matrix that main runs. The tag goes on a commit that passed both. We'll post the numbers here, and once it is published, the version on each channel. 0.19.0 stays the latest release on every channel.

  2. DrunkOnJava commented on Nov 12, 2026

    @DrunkOnJava
    Owner

    The two runs against the rows above: three hold, and the peak row does not. No tag until it is understood.

    Run A is 43299514100, the default export. Run B is 43299518912, --saved-meshes, timed. Both measured 3a70b639 against v0.14.0.

    1. Default export unchanged. Holds. 88 of 88 ifc.sha256 and 69 of 69 diagnostics.json equal v0.14.0's, and no scorer output moved.

    2. --saved-meshes export unchanged. Holds. 88 of 88 and 69 of 69 again.

    3. Peak. Fails.

      file v0.14.0 0.14.1 ratio
      Snowdon Towers Architectural 2,845 MiB 1,893 MiB 0.67
      BIM4LCA concrete office, as built 1,577 MiB 1,368 MiB 0.87
      BIM4LCA concrete office, at permit 1,579 MiB 1,531 MiB 0.97
      Autodesk rac_basic 2023 537 MiB 790 MiB 1.47
    4. Time. Holds. The median of the 28 samples of Revit 2023 to 2027 is 1.005, and no file is above 1.05.

    Next. Two timed runs of the 2023 samples under --saved-meshes find which of the two fixes raises the peak:

    On your three fixtures your port matched this mixed picture: one fell from 6.8 to 1.8 GB, and two were unchanged. What we ship will lower the peak or leave it, file by file, not raise it on some files to lower it on others.

  3. DrunkOnJava commented on Nov 12, 2026

    @DrunkOnJava
    Owner

    Row 3, read again: the office clause fails because the backport's pass is not what holds the offices' peak. The 2023 rac_basic rise is #1441's. Still no tag.

    The bisect. Two timed runs of --saved-meshes:

    So #1441, the batch freeing, raises it, and #1691 adds nothing. Two variants of #1441 rule out its re-read of a freed owner. Without the re-read (43309303255), and with batches sized over symbol records only (43309312639), the file stays at 789 and 790 MiB. Two more variants are running now:

    Where each file's peak sits. probe_1075_memory_stages, set to the --saved-meshes scope, on v0.14.0 (43309508151) and the branch (43309516582). It reads each stage's RSS peak from /proc/self/status:

    file export stage ends at the saved-mesh pass adds, v0.14.0 the pass adds, 0.14.1
    BIM4LCA concrete office, as built 728 MiB 847 MiB 696 MiB
    BIM4LCA concrete office, at permit 864 MiB 714 MiB 666 MiB
    Snowdon Towers Architectural 2,130 MiB 1,175 MiB
    rme_basic 2024 890 MiB 523 MiB
    Snowdon Towers HVAC 306 MiB 75 MiB
    rac_basic 2023 188 MiB 348 MiB 601 MiB
  4. DrunkOnJava commented on Nov 12, 2026

    @DrunkOnJava
    Owner

    The 2023 rac_basic rise is fixed, and every row holds except the office clause. Before we tag, could you run the branch on your model?

    The cause. The rise came from how #1441 plans its batches, not from the freeing itself. Two variants of #1441, timed under --saved-meshes:

    So the freeing gives the gain, and the plan gave the rise. Under #1441's plan, the owners that name no symbol get a batch of their own, and only batches of symbols size the next one.

    The fix. abbc6d9c on hotfix/v0.14.1 keeps v0.14.0's plan: those owners share the first batch, as they did in 0.14.0. It keeps #1441's freeing and #1691's streaming of the owners that name nothing. This corrects my first comment: native_saved_scene.rs on the branch no longer equals 979ec428's, because its batch plan is 0.14.0's.

    The rows, run again. The run measured f6c4458f against v0.14.0. That commit is the branch's code without the version bump, which would otherwise change the version string in every IFC header.

    1. Default export unchanged. Holds (43315345839). 112 of 112 ifc.sha256 and 93 of 93 diagnostics.json equal v0.14.0's, and no scorer output moved.

    2. --saved-meshes export unchanged. Holds (43315354501). 112 of 112 and 93 of 93.

    3. Peak, --saved-meshes. No file's peak is above 1.00 of v0.14.0's.

      file v0.14.0 0.14.1 ratio
      Autodesk rac_basic 2023 537 MiB 523 MiB 0.97
      Snowdon Towers Architectural 2,846 MiB 1,892 MiB 0.67
      Snowdon Towers HVAC 699 MiB 464 MiB 0.66
      BIM4LCA concrete office, as built 1,521 MiB 1,368 MiB 0.90
      BIM4LCA concrete office, at permit 1,578 MiB 1,531 MiB 0.97

      The office clause (0.80 or less) is not met, for the reason in my last comment: the export's own model holds those two peaks, and this release does not touch it. The release notes will say so.

    4. Time, --saved-meshes. Holds. The median over the 28 samples of Revit 2023 to 2027 is 1.01, and no file is above 1.06.

    What we'd like from you. The 6.8 GB to 1.8 GB you measured was your own port of #1691. 0.14.1 is not that code, since it keeps 0.14.0's batch plan, and nobody has run it on your model. Before we tag, could you run abbc6d9c on your 122 MiB model and post two things:

    • its peak;
    • whether its artifact equals 0.14.0's, apart from the version string.

    You can build it the way you built your port. Or you can download the binaries from the branch's Release binaries run (downloading needs a GitHub login). That run covers Linux musl, macOS and Windows, with SHA256SUMS.

    We'll hold the tag for your result. If you can't run it, say so, and we'll tag on our own evidence and say in the notes that 0.14.1 itself was not run on your model.

  5. DrunkOnJava commented on Nov 12, 2026

    @DrunkOnJava
    Owner

    One addition to the above: we'll hold the tag until Monday, November 16. If we haven't heard by then, we'll tag 0.14.1 on our own evidence, and the notes will say that 0.14.1 itself was not run on your model. A report from you after that still counts: if 0.14.1 does worse than your port on your model, a 0.14.2 follows.

  6. 5 remaining items

  7. added
    type:bug
    area:geometry
    priority:P2
    on Nov 14, 2026
  8. DrunkOnJava commented on Nov 19, 2026

    @DrunkOnJava
    Owner

    @shifatrHtH, 0.14.1 is out: release page, rvt = "=0.14.1", pip install rvt==0.14.1, or ghcr.io/drunkonjava/rvt-rs:0.14.1. What went in from your #2081, and how the published files were checked, is in my comment there. In short, for anyone landing here: it is 0.14.0 with only the saved-mesh pass's memory changed, and the exports of the published binary and wheel on three reference models are 0.14.0's line for line, apart from the version they record and the time of the export.

    The one thing still open is yours: 0.14.1's peak memory on your 122 MiB model. It keeps 0.14.0's batch plan, so it is not the port you measured. I'm closing this as done. If 0.14.1 does worse there than your port, say so here and I'll reopen it, and a 0.14.2 follows.

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

    area:geometrypriority:P2type:bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions