Skip to content

Throughput baseline

Informational numbers from benches/eval_throughput.rs (criterion), recorded so future optimization work has a concrete starting point. They are not a correctness gate and are expected to shift as internals evolve.

Machine: Linux 6.17, x86-64 desktop, single thread, cargo bench defaults (2026-07-02).

workload input size time / batch throughput
Circle::points_at 100 000 params ~1.13 ms ~88 M evals/s
BSplineCurve::points_at (degree 3, 20 poles, clamped) 100 000 params ~10.5 ms ~9.5 M evals/s
BSplineSurface::points_at (bicubic, 6×6 poles) 100 000 (u, v) pairs ~26.1 ms ~3.8 M evals/s

The internals behind points_at are deliberately plain scalar loops in this proof-of-concept; the array-in/array-out API shape exists so that future bulk optimizations (SoA layouts, SIMD, parallel evaluation) can land behind the same signatures without breaking callers.

Reproduce with:

cargo bench --bench eval_throughput

Points with derivatives

The same bench times the point and its derivatives up to second order on the curve and the surface above, from separate point_at and derivative calls and from one second_derivatives call, which evaluates the basis functions once.

Machine: Linux 7.0, x86-64 desktop, single thread, --warm-up-time 1 --measurement-time 3 (2026-10-12). Times are per parameter.

workload separate calls second_derivatives
BSplineCurve: point, first and second derivatives ~172 ns ~95 ns
BSplineSurface: point, Su, Sv, Suu, Suv, Svv ~856 ns ~208 ns

First derivatives

first_derivatives on the same curve and surface, and on rational copies of them (weights 1 + 0.5 sin i on the curve, 1 + 0.3 sin(i + j) on the surface). Non-periodic B-splines of degree 1 to 3 in every direction take an unrolled path that computes the basis functions and their first derivatives together, as the point evaluation already did; the results are bit-for-bit those of the general path.

Machine: Linux 7.0, x86-64 desktop, single thread, --warm-up-time 1 --measurement-time 2, best of four interleaved runs on a loaded machine (2026-10-30). Times are per parameter.

workload 0.40.1 unrolled
BSplineCurve::first_derivatives ~41 ns ~22 ns
BSplineCurve::first_derivatives, rational ~47 ns ~38 ns
BSplineSurface::first_derivatives ~89 ns ~61 ns
BSplineSurface::first_derivatives, rational ~99 ns ~81 ns

The numeric curve–curve extrema and intersection and the marching intersection evaluate through first_derivatives and second_derivatives, which made them 12–17% faster on B-splines; the numeric curve–surface intersection spent its time projecting seeds onto the surface and was unchanged (see below for its B-spline path).

Intersection entry point

benches/intersect_dispatch.rs times batches of 1024 intersections of one pair kind four ways: the typed call (IntersectExact::intersect_exact), and the routed call (Intersect::intersect) on the concrete types, on ElementaryCurve/ElementarySurface, and on Curve/Surface. The inputs vary across the batch, so each one mixes crossings, tangencies and misses.

The table below is history (0.29 to 0.35): it was measured when the typed call was Intersect::intersect and the per-pair methods it replaced still existed, deprecated. Both are gone in 0.36; the per-pair column is kept for the record. Its two enum columns are the untyped exact calls, removed by ADR 0018: the enums now take the routed call, measured below.

Machine: Linux 7.0, x86-64 desktop, single thread, --warm-up-time 1 --measurement-time 3 (2026-10-12). Times are per pair and vary by 5–10% between runs.

pair typed per-pair method elementary enums Curve/Surface
plane–sphere ~66 ns ~64 ns ~79 ns ~96 ns
torus–cone (coaxial) ~190 ns ~194 ns ~212 ns ~227 ns
line–circle ~175 ns ~176 ns ~207 ns ~223 ns
circle–cylinder ~960 ns ~946 ns ~986 ns ~1.01 µs
line–torus ~1.08 µs ~1.05 µs ~1.06 µs ~1.06 µs
ellipse–ellipse (coplanar) ~1.33 µs ~1.34 µs ~1.38–1.46 µs ~1.38 µs

The typed call cost the same as the per-pair method, which then just forwarded to it. The untyped calls add a match on both shapes and the conversion to the general result, about 15–30 ns per pair: visible on the closed-form pairs and lost in the noise once a polynomial is solved.

The untyped results held their pieces inline, so they were larger than most typed results and never allocated (sizes from std::mem::size_of, before ADR 0018):

type bytes
ExactSurfaceIntersection 624
ExactCurveCurveIntersection 264 (200 before 0.36, whose hits had no optional parameters)
ExactCurveSurfaceIntersection 168
ElementarySurface, ElementaryCurve 120
PlaneConeIntersection (largest typed surface result) 232
PlaneSphereIntersection 112
LineCircleIntersection 72
TorusConeIntersection, LineTorusIntersection, ConicSurfaceIntersection (a Vec) 24 + heap

Reproduce with:

cargo bench --bench intersect_dispatch

One-step reading (ADR 0018)

The router reads each typed exact result straight into its family result (ADR 0018), where it used to convert it to an untyped result first. The machine was loaded by parallel builds (load average 20–60 on 16 cores), so criterion medians moved by tens of percent between runs, in both directions, on code neither build changed. The table counts instructions instead, which the load does not move: valgrind --tool=callgrind on a loop of 64 varied pairs repeated 20 times, minus the same program repeated 0 times, per pair.

pair call before after
line–circle (2D) routed 853 752 (−12%)
circle–line (2D) routed 827 873 (+6%)
line–ellipse (2D) routed 2415 2495 (+3%)
circle–circle (2D) routed 430 435 (+1%)
ellipse–ellipse (2D) routed 9792 9842 (+1%)
line–cylinder routed 1215 1131 (−7%)
circle–cylinder routed 14542 14419 (−1%)
line–circle routed 1275 1231 (−4%)
circle–line routed 1382 1282 (−7%)
line–ellipse routed 1896 1821 (−4%)
circle–circle routed 779 768 (−1%)
ellipse–ellipse routed 9029 8920 (−1%)
plane–sphere routed 824 620 (−25%)
torus–cone routed 513 512 (0%)
plane–sphere ElementarySurface 857 676 (−21%)
plane–sphere Surface 901 719 (−20%)
line–circle ElementaryCurve 1378 1253 (−9%)
line–circle Curve 1427 1326 (−7%)
circle–cylinder Curve/Surface 14787 14517 (−2%)

The surface pairs gain the most: a typed surface result now becomes the family result directly, where it used to be copied into the 624-byte untyped result on the way. Circle–line in 2D is the one pair that does more work: it is solved as line–circle and its result swapped, sorted once more by the circle's parameter, where the removed bridge had a hand-written reading for that order.

Two shapes of the bridge were measured and dropped. Returning Option<family result> for "no closed form" cost a copy of the inline hits on every call, up to a third more instructions on the cheapest 2D pairs, so the bridge takes the numeric search as a fallback instead. Building the hits with one builder call per match arm kept the builder out of line; each reader builds fixed slots and calls it once.

Routed against exact (0.36)

The same bench times Intersect::intersect (routed) against IntersectExact::intersect_exact (typed exact) on batches of 1024 pairs of one kind, here with realistic crossings only: lines crossing a cylinder of radius 1.5 about the vertical axis at two points, coplanar circles of radius 2 and 1.5 with centres 1 to 2 apart, crossing at two points, and the same circles in the plane (2D).

The tables below up to "Parameters on demand" are history: then, the routed call reported the parameters on both operands, so it was read against two baselines:

  • exact: the typed exact call alone. It returns points (and, for a line, its own parameter), not the parameters on both operands.
  • exact + parameters: the typed exact call, then the parameters the routed result reports, computed by the caller (parameters_of on the cylinder, parameter_of on each circle). This is the fair baseline: the same answer, with no routing.

Machine: Linux 7.0, x86-64 desktop, single thread (2026-10-15), loaded (load average 10–15 on 16 cores), so criterion medians moved by about ±10% between runs. Times are criterion medians per pair; the fastest of 40 timings of the batch, taken with the same build, is in brackets.

pair build exact exact + parameters routed
line–cylinder before 82 ns 142 ns 201 ns
line–cylinder after 90 ns (77) 139 ns (133) 193 ns (188)
circle–circle (coplanar) before 36 ns 164 ns 185 ns
circle–circle (coplanar) after 34 ns (33) 111 ns (107) 151 ns (147)
2D circle–circle before 8.6 ns 82 ns 133 ns
2D circle–circle after 8.9 ns (8.1) 81 ns (75) 114 ns (108)

"Before" is the router as it was: every pair went through the untyped ElementaryCurve / ElementarySurface enums. "After" has two changes:

  • Typed routing. A pair of concrete types (Line with Cylinder, Circle with Circle, Circle2D with Circle2D, and every other concrete pair intersect_exact solves) now calls its typed solver directly; only an enum operand goes through the enum dispatch. A trimmed curve routes through the type of its basis curve, so a segment or an arc gets the same path. The result is bit for bit the one the enums give (a test checks it). Measured alone: routed circle–circle 185 → 172 ns, 2D 133 → 117 ns, line–cylinder within the noise (201 → 196 ns).
  • No normalization in the angle of a point. The parameter of a point on a circle or an ellipse is an atan2 around the frame's z direction; the axis was normalized on every call, though a frame keeps unit axes by construction. Dropping that square root and division saves about 13 ns per circle parameter, on both the routed call and the caller's baseline (circle–circle exact + parameters 164 → 111 ns). It changes the last bits of those parameters; every test passes unchanged.

The routed call is now 40–55 ns over the fair baseline, against 20–60 ns before (the baseline itself got faster). Counted under callgrind, the routed call runs about 370 more instructions per pair than the fair baseline in 3D and 330 in 2D:

  • Moving the result. A routed result was 304 bytes for curve–surface, 328 for curve–curve and 208 in 2D, since it kept up to 4 hits and 2 overlaps inline to avoid allocating; the baseline returns about 100. Copying it was about 125 instructions per circle–circle pair and 60 per 2D pair.
  • Building the result. Converting the solver's hits into the routed hits, clipping them to the parameter ranges, and sorting them: about 150 instructions per circle–circle pair.
  • The seam in 2D. A 2D hit just below the seam of a full circle is reported at its start, like in 3D (Circle2D::parameter_in_bounds): about 65 instructions per pair.

The inline hit lists themselves were measured when they replaced heap lists (one allocation per exact routed call, two for a 2D pair): the routed time moved from about 192 to 189 ns for line–cylinder, 179 to 167 ns for circle–circle, and not at all in 2D, since the larger result costs part of the allocation back in copies.

Overlaps come only from coincident curves, and an empty Vec does not allocate, so the overlaps went back to a plain Vec while the hits stay inline. The results shrank to 296, 264 and 144 bytes. Timed the same way (the median of five interleaved runs, each the fastest of 30 timings) the routed call barely moved: line–cylinder 184 → 183 ns, circle–circle 147 → 143 ns, 2D circle–circle 108 → 109 ns; callgrind counts 1547 → 1549, 1599 → 1582 and 1181 → 1184 instructions per pair. The gain is in memory: a caller keeping many results stores up to a third less.

The four parameter_of calls of a circle–circle pair were each needed (two hits on two circles), and each was computed once.

Parameters on demand

A hit parameter is now an Option: the routed result stores a parameter only when the solver computed it on its way to the point (the line of a line–cylinder pair, the substituted conic of a conic pair), and leaves the rest None. A caller who needs one calls the operand's parameter_of / parameters_of on the hit point. The routed call no longer recovers parameters nobody asked for, so it is read against the typed exact call alone: the difference is routing plus building the result. A trimmed operand still computes its parameter, to clip the hit to its range, and stores it.

Same machine, loaded (load average 8–10). Times are the fastest of 30 timings of 100 batches, in three interleaved runs per build; the criterion median after the change is in brackets.

pair exact routed before routed after
line–cylinder 73 ns (77) 184 ns 127 ns (139)
circle–circle (coplanar) 31 ns (32) 145 ns 76 ns (79)
2D circle–circle 8 ns (7.5) 111 ns 35 ns (35)

Callgrind instructions per pair:

pair exact routed before routed after
line–cylinder 714 1545 1161
circle–circle (coplanar) 352 1567 759
2D circle–circle 79 1188 321

The Option fields make each hit 16 bytes larger (a curve–curve hit 48 → 64 bytes, a 2D hit 40 → 56, a curve–surface hit 56 → 72), and the results with inline hits grow with them: 296 → 360 bytes for curve–surface, 264 → 328 for curve–curve and 144 → 176 in 2D. What is left over the exact call is mostly moving that result (memcpy is 13–15% of the routed instructions) and converting the solver's hits into it.

The 2D router then skipped the range test for two unrestricted curves, as the 3D one already did: 2D circle–circle routed 321 → 247 instructions per pair, 35 → 25 ns. The other two pairs did not move (1161 and 759 instructions).

Every parameter filled (#177)

Hit parameters are no longer optional: the router recovers in closed form every parameter the solver did not compute (an atan2 or more each), and the fields shrink back to plain f64. Against the parent commit, criterion medians of two runs, batches of 1000:

pair exact routed before routed after
line–cylinder 77–86 µs 147 µs 229–233 µs
circle–circle (coplanar) 42–47 µs 88–90 µs 201–215 µs
2D circle–circle 7.7–8.6 µs 55–56 µs 111–125 µs

Callgrind instructions per batch item:

pair routed before routed after
line–cylinder 1237 1755
circle–circle (coplanar) 793 1635
2D circle–circle 366 1099

A circle–circle pair recovers four angles (two hits on two circles), a line–cylinder pair two (u, v) pairs. The typed exact calls are unchanged, except conic–conic, which now fills both parameters too (ellipse–ellipse typed +5% instructions).

Every marched curve's deviation (#188)

A marched curve now measures its deviation at the middle of each knot span: one point on the curve, one on each UV curve, and one on each surface. Callgrind instructions against the parent commit:

benchmark before after
marching torus–plane oblique 9,065,899 9,681,029 (+6.8%)
marching cone–cylinder unbounded 8,456,356 8,935,573 (+5.7%)
marching sphere–torus 13,727,998 14,277,464 (+4.0%)
marching B-spline surface pair 46,848,975 48,193,749 (+2.9%)
swept plane cuts, B-spline patch +2.3% to +3.9%

Sampling every knot too doubled the cost (up to +14%) for nothing: there the fits pass through the traced points, which the trace converged far below confusion.

Surface–surface

A plane at heights up to 0.9 across a unit sphere, one circle each. The typed exact call returns the plane–sphere result alone; the routed call builds the general result, with its curve in a Curve in a Vec (one allocation per pair). Criterion medians per pair of three runs, loaded machine (load average 5–8), batches of 1024:

pair exact routed
plane–sphere 77–82 ns 113–120 ns

Since #193 the routed result also carries each curve in the parameters of both surfaces, found in closed form for an exact curve (a circle in the plane, a parallel line on the sphere). That doubled the routed call: plane–sphere about 235 ns per pair, callgrind 698 → 1729 instructions per batch item, of which circle_on_surface (the two UV curves) is 43%; torus–cone 1715 → 4317. A marched curve fits both UV curves on its knots from the parameters the march walked: 4–12% more instructions per march. The typed exact calls are unchanged and stay the fast path for a caller who needs only the curves in space.

Two cylinders whose axes cross used to be marched; their quartic is now classified in closed form and each loop fitted from it (ADR 0036). One pair per id, intersect_routed/crossing_cylinders/*: the typed call classifies in 1008–1255 instructions (85–170 ns), and the routed call fits the loops in 1.08M (bite: a thin pipe biting a thick one, one loop), 1.81M (oblique, one loop) and 2.18M instructions (through: a thin pipe through a thick one, two loops). Against the marcher on the same pairs, timed in one test run on a loaded machine (load average 17–20), the fit took 100 against 210 µs (bite), 175 against 500 µs (through) and 170 against 440 µs (oblique). Its loops carry 386, 748 and 674 poles, because cubic Hermite spans within a quarter of confusion need about as many points as the march takes. About half of the fit is sin_cos, for the generator angle and the second cylinder's angle at each sample. The thin pipe touching the thick one from inside (node: axes r1 − r2 apart, one loop that crosses itself, #234) was marched too. Its closed form classifies in 1124 instructions and fits in 1.60M; criterion times the fit at 160 µs against 746 µs for the march it replaces.

A sphere against a cylinder or a cone whose axis misses its centre went the same way (#232, #233): the same walk along the generators, read against the sphere. One pair per id, intersect_routed/sphere_quadric/*: the typed call classifies in 800–1850 instructions, and the routed call fits the loops in 1.25M (Viviani's curve), 2.40M (a sphere through the cylinder's wall, one loop), 2.45M (around a cone's apex, a loop on each nappe) and 1.47M instructions (beside a cone, one loop over an arc). Against the marcher on the same pairs, timed in one test run on a loaded machine (load average 16–20), the fit took 133 against 1740 µs (Viviani), 248 against 722 µs (wall), 236 against 930 µs (apex) and 143 against 511 µs (beside). The wall loop passes 0.1 from a pole of the sphere, where its longitude turns fast: it takes 786 poles against the march's 570. Sharing the walk among the three pairs costs the two cylinders 1.3–1.4% on the routed call and 50–85 instructions on the typed one, whose result now holds the point where the surfaces touch.

A cone and a cylinder off its axis went the same way (#237, ADR 0040), read along the cylinder's generators. One pair per id, intersect_routed/cone_cylinder/*, all against the cone of half-angle 30° with its apex at (0, 0, √3): the typed call classifies in 1181 instructions (a tilted cylinder, two loops around it), 2675 (a pipe biting into the cone, one arc) and 4013 (a pipe around the apex, an arc on each nappe), the last two finding the arc ends from two arccosines per edge of the cone's shadow. The routed call fits the loops in 2.44M, 1.31M and 1.75M instructions, against 9.55M, 5.66M and 7.27M for the march it replaces on the same pairs: about four times fewer. The result now holds the quartic inline: ConeCylinderIntersection grows from 296 to 448 bytes, which costs the reducer's conics (intersect/cone_cylinder_around_a_sphere) 1.1% on the typed call and 1.5% on the routed one. Boxing the quartic instead was measured on the two cylinders: 20–30% more instructions on every typed quartic call, and a result no longer Copy. The sphere and cone's typed call drops to 1555 instructions (from 2058) as its loops are kept in arrays rather than vectors. Measuring each span against the curve rather than the two surfaces, which near a tangency let a fit stray 4 µm from the closed form, adds 2–8% to every routed id here.

Two cones in general position followed (#237, ADR 0041), read along the first cone's generators. One pair per id, intersect_routed/two_cones/*, the same upright cone against one of 15° along X: the typed call classifies in 2625 instructions (its apex inside the narrow cone, two loops around), 6665 (two arcs) and 5142 (a bite, one arc). The routed call fits the loops in 1.76M, 2.32M and 1.44M instructions, against 8.02M, 10.76M and 7.39M for the march on the same pairs: 4.6 to 5 times fewer. The cone as the other quadric now reads A and β from each generator for both pairs, and the two pairs build their loops with one function: the cone and cylinder's typed calls take 140–200 instructions more (1322, 2859 and 4214), and their routed calls 0.7–0.8%. ConeConeIntersection holds the quartic inline and grows from 232 to 440 bytes: the cones sharing an apex and the parallel cones take 2–3.5% more on the typed call, copying the larger result, and 0.1–0.4% on the routed one. The same change moved the inlining of functions it does not touch, in the other bench binaries: Plane's holds for a conic is no longer inlined into intersect_conic_quadric (conic_quadric/*/plane, 4–7%), nor the line and placed conic into the 2D line–conic calls (1.3% and 2.2%), nor a closure of the skew revolution projection (1.8%).

The pieces running to infinity came next (ADR 0042). The typed call now finds the generators parallel to one of the second cone's, and places each on its component: 2938, 6923 and 5406 instructions on the three pairs above (+300, +260 and +260), about 0.1 µs. The arccosine and the angle of the reach run only where such a generator exists. A fourth pair, branches, a wide cone across the upright one, meets it in four branches: 5133 instructions typed, 10,965 routed, as nothing is marched or fitted. On one branch, a point (branch_point) takes 1447 instructions, a root on a generator and the placement, and a projection (branch_projection) 161k, 64 samples refined by Brent's search and Newton steps. The new Curve variant moved inlining elsewhere, the library unchanged there: the 2D line–parabola and line–ellipse calls (+3.3% and +1.6%), the cone's conics (+1.2–2.7%), the cone and cylinder's typed calls (+1.6% and +2.5%), and down 4–15% on the sphere's typed calls and the parallel cones.

A ring torus against a plane or a sphere in any position followed (#270, ADR 0048), read along its tube circles with the quadrics' fit. One pair per id, intersect_routed/torus_quartic/*, against the torus of radii 4 and 1 about Z: a plane tilted 0.15 through the centre (tilted_plane, two loops around the axis), the plane x = 1 (cassini_ovals, Cassini's two ovals) and a sphere of radius 1 centred 1.5 above the tube's centre circle (sphere_through_the_tube, one loop). The typed call classifies in 2455, 4069 and 3322 instructions, and the routed call fits the loops in 2.09M, 1.95M and 1.52M. These pairs were marched before: the march the marching_intersection bench timed on a torus against an oblique plane and against a sphere cost 9.7M and 14.3M instructions. The plane cuts that keep their circles take about 130 instructions more (swept_plane_cut/torus_*/elementary, +3%), reading the plane's position once more before the special cases.

Splitting the fit from the generators left the signed root of Δ out of line, 2.5–3.5% more on the quadrics' routed calls: it is now forced inline, and they are back within 0.5% of before. The same change stopped inlining Plane's holds into intersect_conic_quadric, as #237 did (conic_quadric/*/plane, +4–7%): forced inline too, they are within 1%.

A torus against a cylinder or a cone off its axis followed (#271, ADR 0049), read along its tube circles between events found by subdivision. One pair per id, intersect_routed/torus_octic/*, against the same torus: a pipe of radius 0.5 along Z through the tube's centre circle (pipe_through_the_tube, two loops), one along X through the centre (pipe_along_a_diameter, four loops), and a cone of half-angle 0.15 tilted 0.1 through the tube (cone_through_the_tube, two loops). The typed call reads the curve in 600k, 962k and 676k instructions, most of it the subdivision copying and quartering its boxes, and the routed call fits the loops in 6.18M, 10.49M and 4.83M. The result enums hold the curve boxed: inline, its 600 bytes made the coaxial torus–cone results that size, and intersect/torus_cone/typed took 7% more, all copying them; boxed, it is back within 0.1% of before. The new code also stopped inlining the closures that [T; N]::map and std::array::from_fn wrap in cone_off_cylinder_axis and cones_in_general_position, 1–3% on the quadrics' typed calls (intersect_routed/{cone_cylinder,two_cones}/*_exact). Spelling out both elements brought them back to or below before.

Two tori off one axis followed (#272, ADR 0050), read by the same sweep: tori_linked (radii 4 and 1.7, the second along Y through (3.2, 0, 0), two loops), tori_side_by_side (equal tori in one plane 7 apart, three loops crossing at four points) and pipe_bends (a bend of radius 3 turning up from the tube at (4, 0, 0), the shared tube circle and one loop). The typed call reads them in 609k, 14.5M and 366k instructions, and the routed call fits them in 5.90M, 73.7M and 15.2M. The pair side by side is symmetric: the subdivision meets many boxes near the plane halfway between them, and its loops cross where the tori touch. Before, its fit slid along every loop through a crossing to every distance, at three evaluations of the curve per step: 157M, and 45.9M for the pipe bends. It now slides only where the normals are near parallel. The cone and cylinder calls read 0.4–1.4% more in memcpy (2.3–4.2% on intersect/cone_cylinder_around_a_sphere, where it is a larger share), its count changed by where the stack places the copies, not by how much they copy: the results are the same size as before. Inlining the function the extra call goes to read 7–9% more. The added code also stopped inlining KnotVector::window into the B-spline evaluation (+2.9% on eval_throughput/bspline_curve_eval_d2_100k) and the line–conic solver into its 2D entry points (+1.3–2.2%): both are now marked #[inline], back to before. swept_plane_cut/extrusion_bspline_oblique/swept reads 82 instructions more (+1.2%), its plane-curve fit called out of line, and the coaxial intersect/torus_cone routed calls 1.4% more, in normalize_line2d_at_zero (marking its helpers #[inline] changed nothing). intersect_routed/circle_circle/routed reads either 1.63M or 1.67M instructions, from changes elsewhere in the crate: the 40k between them is memcpy in moving the circle–circle result, laid out on the stack one way or the other (#312, which touches only the sphere–cone reading, moved it back to 1.67M).

One reading of where a linear form in the generator angle vanishes, shared by the quartic module's five readers (#292), costs the cone pairs up to 42 instructions (factored_loops, +14 on two_cones/arcs_exact) and two_cones/around_exact one (2,933 against main's 2,932, itself within a hair of its budget). Routed through the shared reading, the loop over a pair's infinities measured within noise. The added code also moved ExtrusionSurface::carried_onto out of line, unchanged: swept_plane_cut/extrusion_bspline_oblique/swept reads 7,201, 89 more than main. Marking it #[inline] brought it back but moved the vectorizer's packing of cones_in_general_position, 10–25 instructions more on every pair of cones, with that function's code otherwise as before: both ids are budgeted at the counts measured.

Reproduce with:

cargo bench --bench intersect_dispatch -- intersect_routed

Conic–quadric intersections

benches/conic_quadric.rs times batches of 1024 typed Intersect::intersect calls for each of the 16 pairs of a conic (circle, ellipse, parabola, hyperbola) and a quadric (plane, sphere, cylinder, cone), and for a circle against a torus (conic_quadric/circle/torus). The conics are placed at random near the surface, so each batch mixes crossings, tangencies and misses.

Machine: Linux 7.0, x86-64 desktop, single thread, --warm-up-time 1 --measurement-time 4 (2026-10-12). Times are per pair.

conic plane sphere cylinder cone
circle ~96 ns ~319 ns ~970 ns ~1.14 µs
ellipse ~100 ns ~1.26 µs ~950 ns ~1.10 µs
parabola ~68 ns ~820 ns ~790 ns ~1.00 µs
hyperbola ~100 ns ~920 ns ~1.00 µs ~1.07 µs

The plane pairs, and a circle against a sphere, solve a first-order equation in closed form. The rest solve a quartic: about 570 ns goes to factoring it, and the tangency check costs a bounded Newton search on the derivative per pair of neighbouring roots or complex pair, plus one surface containment test there. Setting up the coefficients takes under 10 ns.

A circle against a torus solves the same kind of quartic and costs about what a circle against a cylinder or a cone does: ~1.88 µs per pair, against ~1.83 µs and ~1.86 µs for those two in the same run (2026-11-10, on a busier machine than the table's).

Reproduce with:

cargo bench --bench conic_quadric

Discretization

benches/discretization.rs discretizes 3000 model-like trimmed curves: two thirds cubic B-splines with 1 to 7 spans, one third quarter-circle arcs (half rational quadratic B-splines, half trimmed Circles). Every curve is a run-time TrimmedCurve, and its maximum chord deviation is 1e-2 or 1e-3 times its size, with no angle limit. Three measurements: counting the points, filling one set of buffers reused across the curves (count, then fill), and the allocating call.

Machine: Linux 7.0, x86-64 desktop, single thread, --warm-up-time 1 --measurement-time 3 (2026-10-12). Times are per curve.

chord deviation points per curve (mean, p95) count fill, reused buffer allocating
1e-2 × size 13.3, 24 ~1.37 µs ~4.46 µs ~4.47 µs
1e-3 × size 36.2, 67 ~1.52 µs ~5.65 µs ~5.68 µs

This is the baseline for later optimizations, and well above the prototype's 4–20 ns per point. Timing the pieces of one cubic span (about 430 ns to count) shows where it goes:

  • extracting the span's Bézier control points: ~170 ns, redone by every call, twice when filling;
  • trying a halving of the span: ~64 ns per split, most of it copying control point arrays sized for the highest degree;
  • the leaf's turning bound, computed for its reported angle deviation even when the angle is not limited: ~65 ns.

Filling costs about three counts: it plans the count again, then visits the runs to write them. Allocating adds little to filling a reused buffer.

Reproduce with:

cargo bench --bench discretization

Curve–surface intersection on B-splines

benches/intersect_curve_surface.rs times the numeric curve–surface search for 64 cubic B-spline curves against one bicubic B-spline surface (6×6 poles (i, j, sin(0.7 i j)), knots [0, 1, 2, 3] with multiplicities [4, 1, 1, 4]). Each curve rises from z = -2 to z = 2 along a wavy path over the surface, so most cross it once. Since 0.36 the bench calls the routed intersect, which sends these pairs to the numeric search; the tables below name that search after the free function intersect_curve_surface it was called through before, which still runs it on any curve and surface.

Machine: Linux 7.0, x86-64 desktop, single thread, --warm-up-time 1 --measurement-time 3 (2026-10-12). Times are per curve.

search time / curve
sampled (before) ~2.78 ms
Bézier piece pairs (after) ~35 µs

The sampled search projected 128 curve samples onto the surface and refined the 24 closest, whatever the shapes. The piece-pair search, about 80 times faster, only looks where the control-point boxes of a curve span and a surface patch overlap, and drops a pair as soon as their hulls part; each hit then costs a few halvings and one short Newton run. Tangencies and overlaps still exhaust its budget and pay for both searches.

Reproduce with:

cargo bench --bench intersect_curve_surface

Curve–curve intersection and extrema on B-splines

benches/intersect_curve_curve.rs times the numeric curve–curve search (through the routed intersect since 0.36, through the free function intersect_curve_curve, which still runs it on any two curves, before) on 64 pairs of cubic B-spline curves in one plane, one crossing the square [0, 5]^2 from left to right and the other from bottom to top along wavy paths, so that every pair crosses at least once; and curve_curve_extrema on 64 pairs of skew cubic B-spline curves, wavy in all three directions, one above the other.

Machine: Linux 7.0, x86-64 desktop, single thread, --warm-up-time 1 --measurement-time 3 (2026-10-12), with the machine otherwise busy: both searches ran back to back under the same load, so their ratio holds better than their absolute times. Times are per pair.

query grid (before) Bézier piece pairs (after)
intersect_curve_curve, crossing pairs ~157 µs ~9.1 µs
curve_curve_extrema, skew pairs ~167 µs ~55 µs

The grid search refined the local minima of a 32×32 sampling of the distance, whatever the shapes. For an intersection, the piece-pair search, about 17 times faster, only looks where the control-point boxes of two spans overlap and drops a pair as soon as their hulls part; each hit then costs a few halvings and one short Gauss–Newton run. Extrema must still visit every pair of spans, since every local minimum is reported, so the gain is about 3 times: a pair is dropped once the distance provably falls along one curve throughout it or bends like a saddle, and solved once it is provably convex. Tangencies, overlaps and other valleys of equal distance exhaust the search's budget and pay for both searches.

Reproduce with:

cargo bench --bench intersect_curve_curve

Marching intersection

benches/marching_intersection.rs times the routed intersect on two bicubic B-spline surfaces (6×6 poles over [0, 5]^2, knots [0, 1, 2, 3] with multiplicities [4, 1, 1, 4]), with heights sin(0.7 i j) and 0.5 cos(1.3 i) cos(1.1 j) at their poles (i, j). They cross in six curves: five open across the footprint and one closed loop. The numbers recorded below were measured before routing, on a direct marching call; the routed call adds only a cheap closed-form check.

Machine: Linux 7.0, x86-64 desktop, single thread, --warm-up-time 1 --measurement-time 3 (2026-10-12). Times are per call.

seeds time curves traced
grid (before) ~24.2 ms 4 of 6
grid, traces ending on the bounds ~24.5 ms 6
Bézier patch pairs (after) ~3.4 ms 6

The grid seeds project 625 samples of each surface onto the other and converge every distance minimum; before traces ended on a parameter bound, two curves running into the bounds were dropped. The patch-pair search halves the pairs of patches whose boxes overlap until each is dropped or small enough to seed from, about 4000 visits of a few hundred nanoseconds; most leaves lie on a curve traced already and are skipped by a box test against the traced points, so about half the time goes to the search and most of the rest to tracing the six curves.

The same bench times elementary pairs: - torus_plane_oblique: a torus of radii 3 and 1 about z against the plane through (0.5, 0, 0.2) tilted 0.6 radians about y (two loops); - sphere_torus: a sphere of radius 1.2 centred on that torus's centre circle (two loops). Since #270 both have a closed form, and the bench marches the same plane and sphere against the torus's rational B-spline form instead (bspline_torus_plane_oblique, sphere_bspline_torus): 42.7M and 205M instructions, against 9.7M and 14.3M for the torus itself, whose 24 meridian circles seed the march exactly where the B-spline's seeds come from the patch search; - cylinder_extruded_wall: a cylinder of radius 1 about z against a cubic B-spline wall extruded along z (two open curves); - cone_cylinder_unbounded: a cone of half-angle 0.3 against a cylinder whose axis is parallel to a generator (two curves to infinity). Since it has a closed form (ADR 0042) it is no longer marched, and the bench dropped it: intersect_routed/cone_cylinder/along_* times the closed form. Its march cost 8.9 M instructions in the budget; routed, the closed form costs 5.4 k where it runs off in branches (along_branches_routed, nothing to fit) and 1.15 M where the loop stays bounded and is fitted (along_loop_routed).

Fastest of three runs, same settings (2026-10-15, machine loaded). Three versions: - the grid over [-10, 10], with traces of at most 2000 steps of at most 0.1 each way; - the iso-curve seeding of the first review round, whose steps grew with the distance from the seed; - the current one. Steps follow the curvature with no fixed cap, are halved when the midpoint strays from the chord or the step crosses more than one knot of a B-spline side, and stop on the trace box (the model-size cube before 2026-11-02, the seeded box after it). Bounded pairs add both grids.

case grid first round current
bspline_surface_pair ~2.61 ms ~2.60 ms ~3.11 ms
torus_plane_oblique ~478 µs ~441 µs ~580 µs
sphere_torus ~682 µs ~524 µs ~1.02 ms
cylinder_extruded_wall ~1.86 ms ~460 µs ~415 µs
cone_cylinder_unbounded ~5.73 ms (4001 poles per curve) ~771 µs (407) ~665 µs (215)

The midpoint check costs one more Newton solve per step. It makes the B-spline pair and the torus–plane pair about 20 % slower than the grid. The sphere–torus pair also traces from both grids, because the torus meridians alone can pass between small loops. In exchange, a step can no longer cross a feature whose ends share a tangent, such as a small bump on a straight wall, which the first round did.

The cone–cylinder curves used to stop after a fixed number of steps. They now run to the cube 50 000 away, the step doubling along the nearly straight branches. The torus seeds from 24 meridian circles cut by the sphere or the plane (exact), and the plane from 48 lines across the torus's box (each a quartic). The sphere's circles would meet the torus only through the sampled search, so they are left out. A circle meets a torus in closed form since #269, and they are still left out: they found no curve the other seeds missed, at 3.7% more instructions here (ADR 0047). The wall's grid finds the curves that the cylinder's rulings miss, since the rulings run along the extrusion.

Measured outside the bench (best of five calls, release), pairs without a closed form: the cone pairs through the routed intersect on Surface, the tori (radii 3 and 1, and 3 and 0.8 tilted and shifted) through the same routed intersect (direct marching call at the time):

pair grid first round current
cone × cylinder along a generator ~4.1 ms ~0.54 ms ~0.50 ms
cone × cone, parallel axes ~4.4 ms ~0.44 ms ~0.40 ms
torus × torus (grid seeds in all three) ~1.04 ms ~1.06 ms ~1.39 ms

The same bench times pairs where the surfaces lie on each other or touch, and asserts each answer outside the timed loop: - sphere_bspline_copy: a sphere of radius 0.8 against its own rational B-spline form (coincident); - cylinder_own_patch: a cylinder of radius 1 against its patch over a whole turn and z in [0, 2] (incomplete, one region covering the patch); - plane_own_patch: a plane against its own bilinear patch (likewise); - bspline_sphere_itself: that B-spline sphere against itself (coincident); - plane_tangent_to_cylinder_patch: the plane x = 1 against that cylinder patch, which it touches along a ruling (one curve, tangent).

Before the coincidence check, seeding cut every iso-curve of the elementary side with the other surface. On surfaces lying on each other each iso-curve lies on the other surface, so its search never separates and falls back to sampling: about 0.5–2 ms per iso-curve, for 24 to 48 of them. The plane touching the patch paid the same for its 22 lines touching the patch. Now a 7 × 7 grid of one surface's points is projected onto the other first, and the check stops at the first point off it, which costs crossing pairs one or two projections. Where the grids of seeds find only touches, the iso-curves are left out.

Fastest of three runs, same settings (2026-10-15, machine loaded). The 0.35 marching call, the routed call before the check, and the current one:

case 0.35 before current
sphere_bspline_copy ~6.8 ms (2 spurious curves) ~787 ms (none, not coincident) ~306 µs (coincident)
cylinder_own_patch ~2.0 ms (none) ~469 ms (none, not coincident) ~10 µs (one region)
plane_own_patch ~0.32 ms (none) ~42 ms (none, not coincident) ~5.7 µs (one region)
bspline_sphere_itself ~270 ms (35 spurious curves) ~1.04 s (25 spurious curves) ~568 µs (coincident)
plane_tangent_to_cylinder_patch ~1.9 ms (none) ~24 ms (one curve, not tangent) ~90 µs (one tangent curve)

The check makes the crossing pairs above at most a few percent slower, within the noise of the loaded machine.

Reproduce with:

cargo bench --bench marching_intersection

Mixed elementary and B-spline intersections

The same two benches time an elementary shape against a B-spline, converted to its exact rational B-spline and searched by Bézier piece pairs instead of sampled. intersect_curve_surface: the 64 cubic curves above against a cylinder of radius 2 about the vertical axis through the footprint's centre, and 64 circles of radius 0.6 to 1.2 standing across the bicubic surface in vertical planes of random directions. intersect_curve_curve: 64 circles of radius 1 to 2 in the plane of the crossing pairs against the first curve of each pair. curve_curve_extrema: 64 ellipses of radii 2 and 1, tilted at random 1 to 2 above the plane, their halves [0, π], and the lines along their major axes, whole and over [-2, 2], against the lower curve of each skew pair.

Machine: Linux 7.0, x86-64 desktop, single thread, --warm-up-time 1 --measurement-time 3 (2026-10-12). Times are per curve or pair.

query sampled (before) after
intersect_curve_surface, cubic × cylinder ~84 µs ~62 µs
intersect_curve_surface, circle × bicubic ~4.9 ms ~84 µs
intersect_curve_curve, circle × cubic ~66 µs ~15 µs
curve_curve_extrema, segment × cubic ~58 µs ~29 µs
curve_curve_extrema, ellipse × cubic ~66 µs unchanged, sampled
curve_curve_extrema, half ellipse × cubic ~116 µs unchanged, sampled
curve_curve_extrema, line × cubic ~33 µs unchanged, sampled

Every search run here ends complete. A circle against a surface gains most, about 58 times: the sampled search projected 128 points of the circle onto the surface, each projection a search of its own. Against a cylinder the gain is smaller, as the cylinder's quarter-turn patches are large and rational, and their boxes overlap much of each curve. The extrema search beats the grid on a segment only: on a whole ellipse it took ~270 µs (a maximum of the distance along the closed curve for every point of the cubic, and loose bounds on rational pieces), on a half ellipse ~145 µs, and on a full line ~42 µs against the exact reduction to the cubic alone, so those pairs stay sampled.

Reproduce with:

cargo bench --bench intersect_curve_surface -- "cylinder|circle_bspline_surface" --warm-up-time 1 --measurement-time 3
cargo bench --bench intersect_curve_curve -- "_bspline$" --warm-up-time 1 --measurement-time 3

2D curve–curve intersections

intersect_curve_curve also times the routed 2D intersect on 64 pairs of each family in the plane: lines, circles, ellipses (radii 2 and 1), parabolas and hyperbolas with random centres in [1, 4]² and random directions. Every pair of lines and conics is solved exactly, in closed form; the B-spline ellipses are searched numerically.

Machine: Linux 7.0, x86-64 desktop, single thread, --warm-up-time 1 --measurement-time 2 (2026-10-22). Times are for the 64 pairs.

query time
line × circle ~6.9 µs
line × ellipse, parabola or hyperbola ~14 µs
circle × ellipse, ellipse × ellipse ~70 µs
ellipse × parabola, hyperbola × ellipse, parabola × hyperbola ~60 µs
half ellipse × ellipse ~70 µs
B-spline ellipse × line (numeric) ~340 µs
B-spline ellipse × ellipse (numeric) ~920 µs

Reproduce with:

cargo bench --bench intersect_curve_curve -- curve_curve_2d --warm-up-time 1 --measurement-time 2

Swept-surface projection

benches/swept_projection.rs projects 256 points scattered near each swept surface, and the same points onto the surface converted with to_bspline_patch over the part they lie near. The swept surface works on its profile; the patch runs the general two-parameter search.

Machine: Linux 7.0, x86-64 desktop, single thread, --warm-up-time 1 --measurement-time 3 (2026-10-30). Times are for the 256 points.

surface swept B-spline patch
extrusion of a tilted ellipse (closed-form section) ~810 µs ~4.1 ms
extrusion of a cubic B-spline ~340 µs ~1.5 ms
revolution of a circle meridian (closed form) ~58 µs ~4.6 ms
revolution of a cubic B-spline in a plane through the axis ~520 µs ~3.7 ms
revolution of a skew cubic B-spline (one-parameter search) ~980 µs ~4.7 ms

Reproduce with:

cargo bench --bench swept_projection -- --warm-up-time 1 --measurement-time 3

Plane cuts of swept surfaces

benches/swept_plane_cut.rs cuts each swept surface with a plane in a position with a closed form, the same surface converted with to_bspline_patch (which marches), and the elementary surface of the same shape where there is one.

Machine: Linux 7.0, x86-64 desktop, single thread, --warm-up-time 1 --measurement-time 3 (2026-10-30).

surface and plane swept B-spline patch elementary
revolved circle, plane perpendicular to the axis ~450 ns ~5.9 ms ~230 ns (Torus)
revolved circle, plane tangent at the top ~290 ns ~2.1 ms ~130 ns (Torus)
revolved circle, plane through the axis ~320 ns ~2.9 ms ~230 ns (Torus)
revolved cubic B-spline, plane perpendicular to the axis ~4.4 µs ~2.1 ms —
extruded circle, plane holding the direction ~380 ns ~630 µs ~70 ns (Cylinder)
extruded cubic B-spline, oblique plane ~230 ns ~950 µs —

The revolved B-spline pays for the numeric curve-plane search of its crossings; every other row is closed form throughout.

Reproduce with:

cargo bench --bench swept_plane_cut -- --warm-up-time 1 --measurement-time 3

UV curve composition

benches/uv_curve_composition.rs times uv_curve_to_3d of a slanted line on a bicubic B-spline surface over [0, 2] x [0, 1] with three interior knots along u and two along v (ADR 0032): the line is clipped to the domain, split where it crosses the knot lines, put through each Bézier patch, and joined into one degree-6 B-spline, whose redundant knots are then removed.

Machine: Linux 7.0, x86-64 desktop, single thread, --warm-up-time 1 --measurement-time 3, load average 8 (2026-10-30).

workload time instructions
slanted line on a bicubic surface with interior knots ~13.8 µs ~224 000

The instructions are counted with valgrind --tool=callgrind on a loop of 16 slanted lines through the same surface, repeated 20 times, minus the same program repeated 0 times, per line. About 72% of them go to the per-piece Bernstein products (41% to the powers of the two directions' factors), 12% to the knot removal, and the rest to the crossings, the splitting and the join; allocation is about a third of the total. This is the unoptimized first version.

Reproduce with:

cargo bench --bench uv_curve_composition -- --warm-up-time 1 --measurement-time 3

Curve–surface and surface–surface extrema

benches/surface_extrema.rs times curve_surface_extrema and surface_surface_extrema: the closed forms on 64 lines against a sphere and 64 circles above a plane, and on 64 pairs of spheres; then the sampled search against the bicubic B-spline surface of intersect_curve_surface, with 16 cubic B-spline curves running above it, 16 circles standing above it, the same curves against a cylinder, 8 spheres above the surface, and the surface against 4 copies of itself turned upside down and raised.

Machine: Linux 7.0, x86-64 desktop, single thread, --warm-up-time 1 --measurement-time 2 --sample-size 10 (2026-11-18). Times are per pair.

pair time
closed forms, curve × surface (128 pairs) ~0.13 µs
closed forms, sphere × sphere (64 pairs) ~0.12 µs
cubic × bicubic ~290 µs
circle × bicubic ~290 µs
cubic × cylinder ~390 µs
bicubic × sphere ~1.1 ms
bicubic × bicubic ~1.2 ms

The sampled search spends about half its time pairing the samples, and most of the rest projecting the curve's samples onto the surface. A proven search on Bézier pieces, as for two curves, is the follow-up.

Reproduce with:

cargo bench --bench surface_extrema -- --warm-up-time 1 --measurement-time 2 --sample-size 10

Instruction budget

CI fails a pull request that makes a benchmark heavier than its budget, and prints which functions got heavier. The budget is benches/budget.tsv: one row per benchmark id, with the binary, the id and its instruction count.

What is counted

Each id runs once under callgrind, with collection switched on only while criterion's Bencher::iter and its callees run:

valgrind --tool=callgrind --collect-atstart=no \
  '--toggle-collect=criterion::bencher::Bencher<M>::iter*' \
  <bench binary> --bench --test --exact <id>

The count leaves out the harness's fixed cost (argument parsing, reports, gnuplot probing), so a change of 1% in the routine is visible. The counts are deterministic: repeated runs give identical numbers. They depend on the code, the toolchain and the codegen settings, so the bench profile pins codegen-units, lto and incremental in Cargo.toml, and CI pins the toolchain to 1.96.1 and criterion to 0.7.0 (its Cargo.lock is not committed).

The count also depends on where the binary lives: the heap layout shifts the malloc work inside the routine, so the script copies each binary to /tmp/geomcore-benchmark-budget/<bench> and runs it from there with a fixed environment. Budgets and checks always use that path.

The script links the binaries without RELRO (-z norelro), in their own target/benchmark-budget directory. LLD, rust's default linker, can lay the writable segment out as all RELRO, and valgrind 3.22 then reads no symbols from the binary, so the toggle on Bencher::iter collects nothing. The #221 build of marching_intersection was the first to hit this; every count was re-measured with the flag.

Running the check locally

Needs valgrind and callgrind_annotate on the path (Debian and Ubuntu: sudo apt install valgrind).

python3 scripts/benchmark_budget.py check
python3 scripts/benchmark_budget.py check --base main   # per-function diff on failure
python3 scripts/benchmark_budget.py measure eval_throughput/circle_eval_points_100k

check exits 1 when an id is more than 1% above its budget. With --base it builds the base ref in a temporary worktree and prints, for each failing id, the functions whose counts changed most, base against PR.

The ratchet

A count below its budget passes, and check says so: the PR should lower the budget in the same change. A count more than 1% above fails. To accept a deliberate cost, raise the budget with update in the PR and give the reason in the PR body. Do not raise a budget to make a failure go away without that reason.

A new benchmark can move the count of an unrelated one in the same binary: each benchmark inlines the whole call, so another caller of a shared function can change what the compiler inlines elsewhere. Adding the cones_sharing_an_apex batch to intersect_dispatch stopped the inlining of with_exact_uv_curves into the plane–sphere routed loop, 5% more instructions with the library unchanged. Measure the old ids without the new batch before looking for a cause in the library, and when it is the binary, raise the budget saying so.

Updating the budget

python3 scripts/benchmark_budget.py update              # re-measure the budgeted ids
python3 scripts/benchmark_budget.py update <id> ...     # add or re-measure ids
python3 scripts/benchmark_budget.py update --all        # budget every id

Subset

All 142 ids are budgeted. Measured serially on the machine that recorded the budget, the full list takes about 2 minutes under valgrind (the limit set in the issue is about 8 minutes). The CI job runs the ids in parallel.

Result fingerprints

tests/intersection_fingerprints.rs prints the results of a fixed set of pairs: the method, completeness, hits or curves, and sampled coordinates rounded to six decimals. Each group's dump is hashed with FNV-1a (64 bit, written out in the test so the hash does not change with the standard library). The hashes are committed in tests/fixtures/intersection_fingerprints.txt.

  • marching: the ten surface pairs of the marching_intersection bench as it was, the cone and the cylinder along its generator among them: that pair now has a closed form and left the bench, and its fingerprint follows the exact result. The torus against the oblique plane and the sphere follow the bench onto the torus's B-spline form (#270).
  • curve_curve: crossing B-splines, a circle against a B-spline, and two coplanar circles.
  • curve_surface: a B-spline and a circle against the footprint surface, and a B-spline against a cylinder.

The pairs follow the benches' constructors, so the fingerprints cover the same workloads. (The issue mentions an 18-pair marching dump; no such list exists in the repository, so the test uses the bench's ten pairs.)

When a result changes on purpose, accept it with

GEOMCORE_UPDATE_FINGERPRINTS=1 cargo test --test intersection_fingerprints

and commit the rewritten fixture. A failing run prints the new fingerprints and the dumps.