Skip to content

Modeling - Skip redundant optimization for flat deviations in GeomLib_CheckCurveOnSurface#1373

Open
andymai wants to merge 1 commit into
Open-Cascade-SAS:masterfrom
andymai:perf-geomlib-checkcurveonsurface-flat-fastpath
Open

Modeling - Skip redundant optimization for flat deviations in GeomLib_CheckCurveOnSurface#1373
andymai wants to merge 1 commit into
Open-Cascade-SAS:masterfrom
andymai:perf-geomlib-checkcurveonsurface-flat-fastpath

Conversation

@andymai

@andymai andymai commented Jul 16, 2026

Copy link
Copy Markdown

Fixes #1372.

GeomLib_CheckCurveOnSurface runs, per sub-interval: a ~310-evaluation math_PSO swarm, a math_NewtonMinimum polish that is guaranteed to fail on flat deviation functions (singular Hessian), and a second full swarm as the failure fallback — even when the 3×N control-point seed sampling has already shown the deviation is zero to machine precision. On analytic geometry (line/circle on plane/cylinder/sphere/…, i.e. most prismatic CAD) this accounts for ~18% of the total cost of a boolean operation (callgrind numbers in #1372).

This change accepts the sampled deviation and skips the optimization pipeline when every control point lies below the geometric noise floor (Precision::SquareConfusion() on the squared distance):

  • immediately, when the whole composition is analytic (3D curve and pcurve of type Line/Circle/Ellipse/Hyperbola/Parabola on an elementary surface): the deviation function of such a composition is a smooth low-degree function already resolved by the control-point sampling used to seed the swarm;
  • after confirming flatness by resampling at half-step offsets (doubling the sampling density), for all other compositions.

Sub-interval handling, the seeding itself, and every non-flat path are unchanged: any sampled squared distance above the noise floor falls through to the existing PSO + Newton pipeline. Deviations that are real but flat (e.g. a pcurve on a cylinder of a different radius) are above the floor at every sample, so they take the existing path — covered by the new gtest.

Measurements (single-threaded; details in #1372):

  • native (gcc 13 -O2): baseplate cut with 9 rounded-box tools 59.5 → 47.4 ms (−20.3%); 5-solid fuse 28.0 → 23.2 ms (−17.1%)
  • WebAssembly (Emscripten 5.0.3, Node 24): same workloads 100.9 → 80.8 ms (−19.9%) and 51.2 → 41.4 ms (−19.1%)
  • TargetFunc::Value evaluations: 495 728 → 304 832 with the analytic gate alone; the confirmation resample removes most of the remainder
  • result shapes bit-identical on both workloads (topology counts, volume, area, tolerances, BRepCheck_Analyzer)

Validation:

  • DRAW test groups boolean, blend, lowalgos: outcome sets identical between patched and unpatched builds on the same machine (2319 OK; identical pre-existing BAD/FAILED sets) — the change does not alter any test outcome
  • GTest suite: no new failures; adds GeomLib_CheckCurveOnSurface_Test.cxx covering a coincident analytic composition (zero deviation), a deviating analytic composition (real constant deviation must be measured, not swallowed by the fast path), and line-on-plane

Especially relevant for single-threaded consumers (WebAssembly builds), where OSD_Parallel cannot hide the cost of this check.

@dpasukhi

Copy link
Copy Markdown
Member

Dear @andymai

Thank you for your patch. To proceed with integration, please complete signing CLA process:
The links: Contribution Guide
Or https://dev.opencascade.org/get_involved

In case if you already have signed CLA, please share ID that OCCT team shared with your by email after accepting of CLA.

@dpasukhi dpasukhi added the 3. CLA waited User need to process with CLA before review or integration processes label Jul 18, 2026
@andymai
andymai marked this pull request as ready for review July 18, 2026 14:37
…_CheckCurveOnSurface

GeomLib_CheckCurveOnSurface ran, per sub-interval, a ~310-evaluation
math_PSO swarm, a math_NewtonMinimum polish that cannot converge on a
flat deviation function (singular Hessian), and a second full swarm as
the failure fallback - even when the 3xN control-point seeding had
already shown the deviation is zero to machine precision. On analytic
geometry this is ~18% of the total cost of a boolean operation.

Accept the sampled deviation and skip the optimization pipeline when
every control point lies below Precision::SquareConfusion():
immediately for fully analytic compositions, and after confirming
flatness by resampling at half-step offsets otherwise. Non-flat
inputs take the existing path unchanged.

Boolean benchmarks (single-threaded): rounded-tool cut -20%, multi-solid
fuse -17%, with bit-identical result shapes.
@andymai
andymai force-pushed the perf-geomlib-checkcurveonsurface-flat-fastpath branch from 3988a19 to 5ad5f30 Compare July 18, 2026 14:41
@andymai

andymai commented Jul 20, 2026

Copy link
Copy Markdown
Author

@dpasukhi CLA signed, just awaiting confirmation.

@dpasukhi
dpasukhi self-requested a review July 22, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. CLA waited User need to process with CLA before review or integration processes

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Modeling - GeomLib_CheckCurveOnSurface spends most of its time re-discovering flat deviation functions

2 participants