Skip to content

Add OT_TRACE_TIMER and wire timing into import / export / mesh paths#4

Merged
gsdali merged 1 commit into
mainfrom
feat/perf-tracing
May 2, 2026
Merged

Add OT_TRACE_TIMER and wire timing into import / export / mesh paths#4
gsdali merged 1 commit into
mainfrom
feat/perf-tracing

Conversation

@gsdali
Copy link
Copy Markdown
Owner

@gsdali gsdali commented May 2, 2026

Extends the v0.2.0 trace infrastructure with a RAII wall-clock timer and wires per-call timing + phase boundaries into the file I/O and mesh extraction paths so a real Templot workload can be profiled end-to-end with OCCT_TEMPLOT_TRACE=1.

What landed

New OT_TRACE_TIMER(label) macro in src/occt_templot_trace.h. Place near the top of a function (after the NULL guard) — emits [ot] label: <ms> ms on every return path including exception unwind. Cost is one steady_clock::now() on entry plus one on exit; effectively free when tracing is off (the destructor short-circuits on enabled()).

Wired into 16 entry points:

  • All STL/STEP/IGES/OBJ importers (ot_import_* + _robust variants + _with_diagnostics)
  • All five exporters (STL/STEP/IGES/OBJ/PLY)
  • All four mesh extractors (ot_mesh_shape, _separate, _fill, ot_edge_mesh_shape)

Each function emits enter / phase / exit traces around the OCCT-heavy work (ReadFile, TransferRoots, BRepBuilderAPI_Sewing::Perform, ShapeFix_Shape::Perform, BRepMesh_IncrementalMesh::Perform, writer.Write).

Sample output on bearing.stl (24,680 triangles, macOS arm64, OCCT 8.0.0-beta1)

ot_import_stl: 453.759 ms
ot_export_stl (mesh + write): 2435.658 ms
ot_export_step: 5794.970 ms
ot_mesh_shape (cold): 1978.689 ms (verts=74040 tris=24680)
ot_mesh_shape_separate (warm): 1256.065 ms

Why

v0.2.0 tracing covered analyze / heal / sew / make_solid (and surfaced an O(N^4) wire-matching bug). This PR extends the same pattern to import / export / mesh — the next likely suspects when "the Templot viewer feels slow" doesn't bottom out in the heal path. With this in place we can profile a representative workload and see where wall time actually goes before deciding whether the GL-on-Metal translation overhead is even worth pursuing.

Test plan

  • ctest 4/4 green with tracing off (default) on macOS arm64.
  • OCCT_TEMPLOT_TRACE=1 ./test_io bearing.stl produces complete enter/phase/exit/timing traces for every code path it exercises.
  • Linux + Windows CI via PR checks.

Extends the trace infra from v0.2.0 with a RAII wall-clock timer and
covers the file I/O and mesh extraction entry points so a real Templot
workload can be profiled end-to-end with OCCT_TEMPLOT_TRACE=1.

Trace surface added:
  - ot_import_stl, ot_import_stl_robust
  - ot_import_step, ot_import_step_robust, ot_import_step_with_diagnostics
  - ot_import_iges, ot_import_iges_robust
  - ot_import_obj
  - ot_export_stl, ot_export_step, ot_export_iges, ot_export_obj, ot_export_ply
  - ot_mesh_shape, ot_mesh_shape_separate, ot_mesh_shape_fill
  - ot_edge_mesh_shape

Each function emits an enter line, a phase trace around heavy OCCT
calls (ReadFile / TransferRoots / Sewing::Perform / ShapeFix::Perform /
BRepMesh_IncrementalMesh::Perform / writer.Write), and an exit line
with output counts where applicable. The new OT_TRACE_TIMER(label)
RAII guard reports total wall time on every return path including
exception unwind.

Sample output on bearing.stl (24,680 triangles, OCCT 8.0.0-beta1,
macOS arm64):
  ot_import_stl: 454 ms
  ot_export_stl (mesh + write): 2,436 ms
  ot_export_step: 5,795 ms
  ot_mesh_shape: 1,979 ms (cold mesh)
  ot_mesh_shape_separate: 1,256 ms (warm cache)

Tracing remains off by default; ctest 4/4 green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gsdali gsdali merged commit 854d1d2 into main May 2, 2026
0 of 3 checks passed
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