Skip to content

Speed up large-model read and multi-format export - #313

Open
mahach666 wants to merge 1 commit into
mainfrom
perf/read-export-optimizations
Open

mahach666 wants to merge 1 commit into
mainfrom
perf/read-export-optimizations

Conversation

@mahach666

@mahach666 mahach666 commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

What this changes

Reader, post-processing, and exporter hot paths, without changing export bytes:

  • src/RvtIO/RvtFileReader.cs, src/RvtIO.Cli/ExportCommand.cs, src/RvtIO/Internal/JsonReadFacts.cs (new): one Read() per CLI run feeds IFC, Scene, compact JSON, and full JSON. JSON consumers get a slimmed JsonReadFacts view (validated-name maps plus only the native stores compact JSON needs) instead of the full ParsingState; the quantity pass keeps the live state only when required. Full JSON no longer triggers a second file read. String scanning now overlaps background geometry decoding against a snapshotted ID set.
  • src/RvtIO/Parsing/WideElementRecords.cs: framed partition streams are indexed from their known record boundaries instead of concatenating the whole section first; unframed streams keep the old path. Adds a regression test that splits a record across segments plus an allocation guard.
  • src/RvtIO/Parsing/WideBlockWalker.cs, WideNativeParams.cs: cache schema field chains and name lookups; resolve capture keys once per field; single-pass best-rank name resolution with the same priority as before.
  • src/RvtIO/Parsing/ElementBuilder.cs, Model/Parameter.cs, Model/Geometry.cs: shared reader parameter metadata, boxed-value reuse, fewer per-parameter/per-face temporaries.
  • src/RvtIO/RvtDocument.cs: ForSceneExport shares read-only parameters with the model instead of cloning every value; mutating repairs still copy. Covered by a scene-isolation test.
  • src/RvtIO/Ifc/IfcExporter*.cs: column quantities defer full shell measurement to the fallback path; stair-run counting uses a per-export index instead of scanning all elements; contracted-shell preparation avoids repeated full-face materialization and duplicate orientation work.
  • src/RvtIO.Cli/FullJsonOutput.cs (new): element batches serialize in parallel with byte-identical output, with a streaming fallback for oversized batches. Wired into --full-json only.
  • src/RvtIO/Model/ParameterListConverter.cs: pre-encoded property names and direct int/string writes for the CLI dump; the parameterized constructor is internal and the default path is unchanged (pinned by CompactLegacyJsonIdentityTests in both modes).
  • tools/benchmark-export.py (new) + CONTRIBUTING.md: repeatable A/B harness — alternates build order, fixes the IFC timestamp, SHA-256-checks all five outputs per run, reports medians and peak working set, optional --min-speedup gate.

Validation

  • dotnet build RvtIO.slnx -c Release: success, 0 errors (315 warnings, same pre-existing count as the base build).
  • dotnet test tests/RvtIO.Tests/RvtIO.Tests.csproj -c Release --no-build: net8.0 12054 passed / 449 skipped / 0 failed; net10.0 12058 passed / 449 skipped / 0 failed.
  • dotnet build src/RvtIO.Scene/RvtIO.Scene.csproj -c Release -p:BuildNativeCoreOnly=true --artifacts-path ./artifacts/native-core-check: success.
  • New/updated tests: FullJsonOutputTests (parallel + oversized batches byte-match the streaming serializer, indented and compact), framed-index split-record test, name-ranking tests, scene-export isolation test.
  • Export parity: 26/26 SHA-256 comparisons identical between base and candidate builds across Revit 2020/2022/2023/2025 samples (IFC, compact JSON, full JSON, Scene, reports), plus single-vs-batch equality per format on the 888 MiB model.

Measured effect (single Windows machine, Release, .NET 10, medians)

Small models: 2023 batch 8.90s -> 8.57s, peak WS 1346 -> 1289 MiB, allocated bytes -13%; 2023 full JSON 3.06s -> 2.79s, peak 600 -> 486 MiB, allocated -26%; 2025 batch 16.33s -> 16.28s, peak 2672 -> 2598 MiB; 2025 full JSON 3.30s -> 3.02s, peak 694 -> 519 MiB, allocated -35%.

888 MiB model, same four-format batch: one paired comparison 231.7s -> 176.9s (1.31x); a later 3-run A/B gave medians 205.2s -> 164.1s (1.25x), peak 35.4 -> 29.8 GiB. Baseline runs varied widely (182-309s), so treat single-digit deltas with care. Four separate single-format runs of the candidate total 364.1s vs 164.1s batched (2.2x batching benefit, not a per-build speedup).

The 2x target for the same batch export is not met by this change (1.25x median). Scene time dropped substantially in the paired run (44.9s -> 15.8s); read remains the dominant cost (67-78s of the total).

Share one parse across IFC/Scene/JSON outputs, trim retained native state, parallelize full-JSON element serialization, and remove hot-path allocations in the wide-schema walk, element construction, and IFC shell/quantity passes. Outputs stay byte-identical; adds a benchmark harness and regression tests.

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