Skip to content

ci(ifc): let the real-project validator accept the building-level containment of unbound elements - #268

Merged
DrunkOnJava merged 1 commit into
mainfrom
fix/validate-real-ifc-building-containment
Sep 19, 2026
Merged

DrunkOnJava merged 1 commit into
mainfrom
fix/validate-real-ifc-building-containment

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Sep 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

#267 stopped fabricating storey containment: elements with no storey evidence are now related to the IfcBuilding itself. The validator's ceiling of one IfcRelContainedInSpatialStructure per storey counted that relation as a regression on the Einhoven sample (5 against 4 storeys) and failed the IfcOpenShell validates synthetic project job on main (run 723).

Changes

  • tools/ci/validate-real-ifc.py: count storey-level and building-level relations separately; storeys between 1 and the storey count, at most one building relation, nothing else; summary line reports both.

Testing

  • python3 -m py_compile clean
  • This PR's IfcOpenShell validates synthetic project job is the verification (ifcopenshell is not installed locally)

Legal and contribution hygiene

  • Licensable under Apache-2.0; no Autodesk material; no PII

Note

Low Risk
CI-only assertion changes in validate-real-ifc.py; no runtime export or application logic is modified.

Overview
Updates the real-project IFC CI validator so it matches export behavior from #267: elements without storey evidence may be contained via an IfcRelContainedInSpatialStructure relating to IfcBuilding, not only per-storey relations.

Instead of requiring the total containment relation count to stay between 1 and the storey count, validation now splits relations into storey-level vs building-level, requires every relation to target one of those structures, keeps storey relations in the existing 1…storey range, and allows at most one building-level relation for unbound elements. The pass summary line reports storey and building relation counts separately.

Reviewed by Cursor Bugbot for commit a1c3c94. Configure here.

…tainment of unbound elements

#267 stopped fabricating storey containment: elements with no storey
evidence are now related to the IfcBuilding itself. The validator's
ceiling of one IfcRelContainedInSpatialStructure per storey counted that
relation as a regression on the Einhoven sample (5 against 4 storeys)
and failed the IfcOpenShell job on main.

Count storey-level and building-level relations separately: between 1
and the storey count for storeys, at most one for the building, and
nothing else.
@cursor

cursor Bot commented Sep 19, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_03fbea0d-6af5-43ea-804b-1efa1c8b3d51)

@DrunkOnJava
DrunkOnJava merged commit 7e6d96e into main Sep 19, 2026
21 checks passed
@DrunkOnJava
DrunkOnJava deleted the fix/validate-real-ifc-building-containment branch September 19, 2026 18:45
DrunkOnJava added a commit that referenced this pull request Sep 19, 2026
… dozen times (#266)

## Summary

The weekly Performance Budgets workflow fails the `medium` category on
`2024_Core_Interior.rvt`. The cost is not the geometry the August
element-record work added — it is that work re-inflating the same
partition bytes more than twenty times per export. This memoises the
inflate on the `RevitFile` handle and fixes the two per-byte scans that
dominated what was left. IFC output is byte-identical.

Measured against `main` at `8425a3f` (i.e. **after** #267, #268 and
#269), `ifc_export` goes **17.88 s to 1.45 s** and peak RSS **2642.0 MiB
to 516.2 MiB**, and every `medium` budget passes.

## Motivation

Every partition consumer opened the CFB stream, inflated all its gzip
members and concatenated them for itself:

- `partition_element_records::scan_category_records_multi` — once per
`BuiltInCategory`: columns (RE-26), walls (#211), doors and windows
(RE-23), and floors / building pads / sketch lines (RE-22, RE-25)
- `partition_arc_walls::scan_partition_arc_walls_with_limits`
- `partition_schema_mvp::floors_from_partition_plan_loops` and
`rect_openings_from_partitions`
- `partition_level_records::scan_partition_levels` (RE-24) and
`scan_partition_level_ids` (RE-27, #267)
- `partition_ifc_export_overrides::scan_ifc_export_overrides`
- `partition_scanner::scan_partitions_with_control`
- `object_graph::string_records_from_partitions`, asked for separately
by unit recovery, storey names and the partition MVP

`RvtDocExporter::export_with_diagnostics` then walks the document a
second time to build diagnostics, doubling all of it. On this file the
eight `Partitions/*` streams inflate to 178.9 MiB, so that is well over
3 GiB of redundant inflate per export — plus a byte-at-a-time
`chunks.into_iter().flatten().collect()` per pass, which profiled higher
than the inflate itself.

Hotspot shares from a `samply` profile of `rvt-ifc --mode geometry` on
the pre-change tree (inclusive, 14,467 samples):

| region | share | what it was |
| --- | --- | --- |
| inflate + per-pass concat | 33 % + 24 % |
`inflate_all_chunks_for_stream` and the `flatten().collect()` join,
repeated per consumer |
| `object_graph::extract_string_records` | 34 % (26 % in encoding_rs) |
UTF-16 decode of the whole `Partitions/NN`, run once per consumer |
| `find_category_records` | 3.6 % before, 21 % once inflate was cached |
hand-rolled substring search, once per category over every partition
byte |

## Changes

- `src/compression.rs` — new `InflatedStream`: all gzip members of one
stream inflated and concatenated once, with each member's end offset.
That is exactly the two shapes the callers were rebuilding (plain
concatenation; concatenation plus `chunk_ends` for the scanner), and it
reserves the exact total instead of growing through `Flatten`.
- `src/reader.rs` — `RevitFile::inflated_partition` memoises it per
stream path, `RevitFile::partition_stream_names` replaces six copies of
the same filter, and `RevitFile::partition_string_records` memoises the
`Partitions/NN` string extraction. `RevitFile` never writes a stream, so
one inflate is valid for the life of the handle.
- `src/partition_element_records.rs`, `src/partition_arc_walls.rs`,
`src/partition_level_records.rs`,
`src/partition_ifc_export_overrides.rs`, `src/partition_scanner.rs`,
`src/partition_schema_mvp.rs` — read through the cache instead of
re-inflating.
- `src/object_graph.rs` — `extract_string_records` screens candidates on
the raw code units before decoding. The strict test it applies (every
char graphic, space, tab or newline) is decidable on the bytes: only
ASCII encodes as `[byte, 0x00]` in UTF-16LE, and every other sequence —
non-ASCII, an astral pair, a lone surrogate that decodes to U+FFFD —
yields a char outside that set. Previously it decoded and heap-allocated
at every offset whose length field happened to land in `1..=400`, which
binary data does at a large fraction of offsets, then threw nearly all
of them away.
- `src/partition_element_records.rs` — `find_subslice` now calls
`memchr::memmem::find`, the vectorised form of the
first-byte-then-compare loop it spelled out by hand. The category sweep
runs it over ~180 MiB per category.
- `src/ifc/mod.rs` — `recover_project_units` and
`collect_partition_building_storey_names` take the shared string
records.
- `Cargo.toml` — adds `memchr = "2"`. **This adds no crate to the build
graph**: `cargo tree -p rvt -e normal -i memchr` shows memchr 2.8.0 is
already a normal (non-dev) transitive dependency through both quick-xml
and serde_json. `cargo deny check` passes (advisories ok, bans ok,
licenses ok, sources ok).

### Second commit: the RE-27 sweep

#267 landed while this was in review and added
`scan_partition_level_ids`, a new sweep over every `Partitions/*` stream
— the ~2 s its author measured on Core Interior. The follow-up commit
here routes it through `RevitFile::inflated_partition` like every other
partition consumer, so it costs a scan rather than a decompress. With
that, no partition sweep in `src/` re-inflates:

```
$ grep -rn "inflate_all_chunks_for_stream\|read_stream(&stream)\|read_stream(&partition)" src/ | grep -v "^src/compression.rs"
(no matches)
```

No behaviour flags, no new public semantics, no geometry changes.

## Testing

All numbers below were re-taken against `main` at `8425a3f`, after
merging it into this branch.

- [x] `cargo test --all` passes locally — `tools/check-local.sh` (fmt,
clippy `-D warnings`, rustdoc `-D warnings`, `cargo test --workspace
--all-targets --all-features`) exits 0. With `RVT_PROJECT_CORPUS_DIR`
set to the magnetar Revit tree: **1252 passed, 0 failed**, including
#267's new `core_interior_2024_storey_containment_is_evidence_backed`
corpus gate.
- [x] `cargo clippy --all-targets --all-features -- -D warnings` passes
- [x] `cargo fmt --check` passes
- [x] New / changed code has unit tests — no new behaviour to test; the
change is covered by the existing suite plus the byte-identity evidence
below. `tests/project_count_fixtures.rs` and `tests/witness_registry.rs`
pass against the real reference exports (`IFC
Exports/2024_Core_Interior_slim.ifc` sha256 `bfdf36ff…` and
`Revit/2024_Core_Interior.ifc` sha256 `d07c7462…`, both matching the
manifests), so every scored count — 15 storeys, 360 walls, 80 slabs, 132
doors, 6 windows, 256 columns, 20 shading devices, 138
`IFCRELFILLSELEMENT` pairs — is reproduced.
- [x] IFC exporter byte-identity — see below.
- [ ] `tools/bench.sh` — **not run**: it needs the phi-ag `rac*.rfa`
sample family, which is not in this checkout. `tools/perf_budget.py` was
used instead, which is the harness the failing workflow actually runs.

### Byte-identical output

`rvt-ifc --mode geometry`, a binary built from `main` at `8425a3f`
versus this branch, same input:

| file | main `8425a3f` | this branch | |
| --- | --- | --- | --- |
| `2024_Core_Interior.rvt` | 1,633,625 bytes | 1,633,625 bytes |
identical |
| `Revit_IFC5_Einhoven.rvt` | 44,701 bytes | 44,701 bytes | identical |

`diff` of the two STEP files with the `FILE_NAME` timestamp line
stripped reports exactly one remaining line, the other wall-clock field
the writer stamps:

```
12c12
< #5=IFCOWNERHISTORY(#3,#4,$,.ADDED.,$,#3,#4,1789844650);
---
> #5=IFCOWNERHISTORY(#3,#4,$,.ADDED.,$,#3,#4,1789844652);
```

Normalising both clock fields (drop `FILE_NAME(`, replace the
`IFCOWNERHISTORY` epoch), the two sides hash the same:

```
2024_Core_Interior   main/branch  sha256 4d1382e93b012761c7b1d7810760b0a0f4b9dabdbed0a9b336e407e0b738d489
Revit_IFC5_Einhoven  main/branch  sha256 f6c32f237338b1236757b2849148d421e7672ee5b569fc4f15545c80af640382
```

Note these hashes differ from the pre-#267 ones — that is #267's
intended storey-binding change, which this branch reproduces exactly.

There is no deterministic-timestamp switch (no `SOURCE_DATE_EPOCH`
support in `ifc::step_writer`), so the two clock fields cannot be pinned
without a behaviour change; adding one is out of scope here.

### Performance

`tools/perf_budget.py --require-category medium`, release profile,
`RVT_PROJECT_CORPUS_DIR` on the magnetar Revit tree. Both columns
measured on the same machine (Apple Silicon, macOS) minutes apart,
baseline from a clean `main` tree at `8425a3f`:

| operation | main `8425a3f` | this branch | budget |
| --- | --- | --- | --- |
| `open` | 14.86 ms / 34.6 MiB | 13.13 ms / 34.6 MiB | 1500 ms / 512 MiB
|
| `summarize` | 18.12 ms / 36.0 MiB | 18.64 ms / 36.0 MiB | 5000 ms /
768 MiB |
| `schema_parse` | 14.61 ms / 35.8 MiB | 13.75 ms / 35.7 MiB | 1500 ms /
768 MiB |
| `element_decode` | **6116 ms / 1858.0 MiB** | 919 ms / 478.5 MiB |
12000 ms / 1024 MiB |
| `ifc_export` | **17880 ms / 2642.0 MiB** | 1454 ms / 516.2 MiB | 15000
ms / 1024 MiB |
| `viewer_parse_render` | **18014 ms / 2642.6 MiB** | 1469 ms / 498.8
MiB | 18000 ms / 1024 MiB |

On this machine `main` fails all three heavy rows — `ifc_export` and
`viewer_parse_render` on time, all three on peak RSS. After, every row
passes with an order of magnitude of headroom.

`rvt-ifc --mode geometry` on `2024_Core_Interior.rvt` under
`/usr/bin/time -l`, best of three:

| | wall | peak RSS |
| --- | --- | --- |
| main `8425a3f` | 26.07 s | 2641.4 MiB |
| this branch | **1.69 s** | **490.1 MiB** |

`Revit_IFC5_Einhoven.rvt` control: 0.44 s / 25.1 MiB on main, 0.12 s /
20.7 MiB on this branch.

For reference, the same comparison taken before #267 landed (main at
`730699c`): `ifc_export` 17352 ms to 1366 ms, `element_decode` 5682 ms
to 866 ms. #267 added roughly 0.5-0.9 s of `ifc_export` on the
unoptimised side and none on this one, because its new sweep now reads
an already-inflated buffer.

**No budget change is proposed and none is needed.** Extrapolating to
the GitHub runner from the ratio the workflow reported on the pre-#267
tree — CI `element_decode` 8.5 s against 5.62 s here, CI `ifc_export`
24.5 s against 17.25 s here, so roughly 1.4–1.5× — these numbers project
to about 1.3 s for `element_decode`, 2.1 s for `ifc_export` and 2.1 s
for `viewer_parse_render`, against budgets of 12 s, 15 s and 18 s. Worth
noting that on this machine #267 pushed `viewer_parse_render` past its
18 s budget too (18014 ms against 18000 ms), so the `medium` category
was getting worse, not stable.

One honest caveat on the memory column: the workflow reported ~480–510
MB peak RSS for the failing baseline, where this macOS machine measures
~2640 MiB for the same baseline binary. That is an allocator difference,
not a measurement error — glibc returns freed pages to the OS where
macOS libmalloc retains them, and the baseline's repeated 180 MiB
transient allocations are exactly the pattern that exposes it. The
direction of the change is the same on both platforms: one retained copy
of the inflated partitions replaces many transient ones, and peak RSS
should fall on Linux too.

## Audit-honesty checklist

- [x] README / docs reflect the current state after this PR — no doc
claims change; this is a pure performance change with identical output
- [x] If a limitation was resolved, the relevant docs are updated — N/A,
no limitation resolved
- [x] If a new limitation was introduced, it is documented — one
tradeoff, documented in-code on `RevitFile::inflated` and
`InflatedStream`: the inflated `Partitions/*` bytes (178.9 MiB on this
file) now stay resident for the life of the handle rather than being
rebuilt per consumer. Measured peak RSS falls sharply anyway, because
the transient copies it replaces cost more than the one it keeps.
- [x] Commit messages describe WHAT changed and WHY
- [x] No emojis in code, docs, or commit messages
- [x] No private paths, personal email addresses, or internal jargon in
committed files
- [x] If this is a reverse-engineering finding: N/A, no new finding — no
decoder, offset or record shape changes

## Legal and contribution hygiene

- [x] I agree this work is licensable under Apache-2.0
- [x] No Autodesk proprietary source, decompiled internals, or NDA'd SDK
content
- [x] No new test fixtures

## Breaking changes

None. Three additions to `RevitFile`'s public surface
(`inflated_partition`, `partition_stream_names`,
`partition_string_records`) and one new public type
(`compression::InflatedStream`);
`object_graph::string_records_from_partitions` keeps its signature and
now returns a clone of the shared result.

## Screenshots or output samples

IFC output is byte-identical to `main` at `8425a3f` — see the diff and
hashes above.

## Related issues

Refs the `Performance Budgets` workflow `medium` category failure.
Builds on #267 (RE-27), whose new partition sweep the second commit
routes through the same cache. No issue number was given for the budget
failure.
DrunkOnJava added a commit that referenced this pull request Sep 19, 2026
## Summary

Docs-only. PR #261 described the state at that moment; #266, #267/#268,
#272, #273 and #274 landed after it and left several pages understating
or contradicting what ships. Every number here is re-read from the
linked report, the corpus gate, or the count manifest that backs it —
nothing is carried over from the PR descriptions.

## Motivation

Two pages disagreed with themselves. `docs/user-guide.md` gave both 853
of 872 and 801 of 872 storey containment in adjacent paragraphs, and
quoted 336 of 360 walls, which #274 superseded. `docs/status.md` still
said the wall-join decision "is in neither wall's box nor in 4 KiB past
its record" — #274 found the carrier. Four pages still promised a ~28
second browser decode that #266 cut to about 3 seconds. The
audit-honesty rule cuts both ways here: the same pass also had to avoid
over-claiming #273, whose wall-type join is exact but emits nothing.

## Changes

- **`docs/status.md`** — re-dated the RE-26 wall and column residuals as
historical; added RE-29 (wall ends 689 → 711 of 720, bodies 336 → 351 of
360, 15 improved / 345 unchanged / 0 regressed, 9 residual ends at two
true L corners; columns 176 → 256 of 256 at a worst residual of 9.4e-13
ft, `difference_box` fail-closed, `IFCPROPERTYSINGLEVALUE` 9231 → 9311)
and RE-28 (the `0xffff8080` wall-type record, 360 of 360, distribution
129/127/100/4, #240 as an index artifact) with an explicit
**library-side only, nothing emitted** paragraph; recorded #88's
no-oracle finding and the 86-record `OST_Materials` bound; new `##
Performance` section.
- **`docs/user-guide.md`** — deleted the contradictory 801 of 872
paragraph; 336 → 351 of 360 plus the 256 of 256 column cut; added the
#272 panel/schedule paragraph and a `### Performance` note; corrected
the demo-gallery decode time.
- **`README.md`** — the headline paragraph, the gaps table row and the
demo-gallery line now carry the RE-27/RE-28/RE-29 state; new `###
Performance on large projects`.
- **`docs/contribution-map.md`** — the closed-issue list is now twelve
issues, not six; the #33 / #219 row reads 853 of 872 and keeps the
reference side marked `NOT MEASURED`; new rows for #238, #88, #227, #34
and #90; the closed #32 row is gone.
- **`docs/support-matrix.json`** — `reviewed` to 2026-09-19; the walls
and columns rows carry the RE-29 measurements and **stay `partial`**; a
new `element-record-wall-type-join` row records RE-28 at `partial` with
"None yet in the exported file" as its user impact; the
instance-recovery and level-record rows no longer read 801 as current.
- **`docs/supported-profile.md`** — IFC output and browser viewer rows;
the compound-layer and family-profile bullets now name the no-oracle
finding and the 9-end residual.
- **`docs/ifc-compare.md`** — divergence table updated to the measured
state, plus a plain statement that `catalogued_divergence_notes` in
`src/ifc/compare.rs` still quotes the pre-#274 figures and still names
#219 for slabs and windows.
- **`docs/viewer-api.md` / `docs/viewer-build-pipeline.md`** — the #266
throughput and the `DECODE_BYTES_PER_SECOND` basis; the pre-#266 figures
are kept but dated; the `build_gltf` `extras` fix and the panel /
schedule contract from #272.

## Testing

- N/A: docs-only PR — no Rust, viewer, workflow or test file is touched.
- `docs/support-matrix.json` re-validated against
`docs/schemas/support-matrix.schema.json` (required keys,
`additionalProperties`, id pattern, status vocabulary, unique ids) and
against the `honesty_invariants` that `tests/support_matrix.rs`
enforces: `never_verified_capability_ids`,
`max_status_by_capability_id`, and the COR-001 converter-grade rule. All
pass; the new row is `partial`.
- Every test and function name cited in the new prose was checked to
exist: `the_surviving_side_of_a_true_l_corner_is_still_over_trimmed`,
`core_interior_2024_column_join_cut_plan_extents`,
`core_interior_2024_wall_joins_are_named_in_the_reference_list`,
`core_interior_2024_wall_type_record_join`,
`core_interior_2024_material_record_family`,
`core_interior_2024_wall_join_trimmed_bodies`,
`core_interior_2024_column_type_symbol_join`, plus
`partition_type_records::{type_definition_ids, unique_type_reference}`
and `element_record_column_cuts::{difference_box, column_cut_boxes}`.
- `core_interior_2024_wall_join_trimmed_bodies` asserts `resolved ==
360` and `trimmed == 322`, which is what the support-matrix evidence
string now says.
- Every relative link and repo path added resolves on disk.

## Audit-honesty checklist

- [x] README / docs reflect the current state after this PR — no claims
of features that are not actually shipped
- [x] Resolved limitations updated: #239 (columns), #240 (the `18"
Basement` slot), and the plate / window storey containment #219 tracked
- [x] New limitations documented: the 9 true-L-corner ends, and #88
being unwitnessable on this corpus
- [x] No emojis, no private paths, no personal email addresses
- [x] N/A: no reverse-engineering finding is introduced here — the
reports (RE-27, RE-28, RE-29) already shipped with their own PRs

**Three claims deliberately not written:**

1. **Nothing about rooms.** `gh pr view 275` reported `OPEN` (checked
twice, at the start and just before committing), so the existing space
claims are untouched and `IFCSPACE` still reads "name-only, placeholder
body" everywhere.
2. **The wall → `IfcWallType` join is never described as shipping in the
export.** RE-28 §7 says "Library only. No emitted IFC entity, property
or relation changes", and §8 says the join "is not yet a property on the
emitted wall". Every mention says so explicitly.
3. **README's "419 MB of linear memory" is left alone.** That is a
wasm32 figure from #256. #266 re-measured native peak RSS (490.1 MiB)
and the browser decode time, but not wasm linear memory, so there is no
measurement to replace it with.

Also left as-is, and now flagged in `docs/ifc-compare.md` rather than
silently papered over: the note constants in `src/ifc/compare.rs` still
say "31 over-trimmed wall ends" and still name #219 for `IFCSLAB` and
`IFCWINDOW`. Fixing those is a code change and out of scope for a
docs-only PR.

## Legal and contribution hygiene

- [x] I agree this work is licensable under Apache-2.0
- [x] No Autodesk proprietary source, decompiled internals, or NDA'd SDK
content
- [x] N/A: no new test fixtures

## Breaking changes

None.

## Screenshots or output samples

N/A: docs-only PR — no UI or IFC output changed.

## Related issues

Refs #88, #219, #238, #239, #240, #266, #272, #273, #274.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Documentation and support-matrix metadata only; no Rust, viewer, or
export logic changes.
> 
> **Overview**
> **Docs-only refresh** so README, status, user guide, contribution map,
supported profile, IFC compare notes, viewer docs, and
`docs/support-matrix.json` match what landed after #266–#274 — without
changing runtime behavior.
> 
> **Capability numbers and gaps** are brought up to date: wall runs
trimmed using the record **reference list** (351/360 world-exact, 9
L-corner ends still wrong), **column bodies** as prism minus named
cutting walls (256/256), **storey binding** via record Level ids
(853/872), and **wall→wall-type** join exact in the library but **not
written to IFC** (#88 compound layers marked **no oracle** on the
ReferenceView corpus).
> 
> **Performance narrative** is added/updated everywhere it was still
~28s: partition inflate **memoized on `RevitFile`** (#266), Core
Interior **~1.7s / ~490 MiB** native and **~3s** browser decode,
byte-identical IFC aside from timestamps.
> 
> **Viewer docs** now describe **glTF `extras`** for picking (#272), the
typed info panel / schedule / host navigation, and
**`DECODE_BYTES_PER_SECOND`** for loading hints.
> 
> **Contribution map & matrix** list twelve closed issues, new remainder
rows (#238, #88, #227, …), RE-29 evidence on wall/column rows, and a new
**`element-record-wall-type-join`** row at `partial`.
**`docs/ifc-compare.md`** documents the measured divergence table and
explicitly notes that **`catalogued_divergence_notes` in
`src/ifc/compare.rs` still lags** (separate code fix).
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
d5c32eb. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
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