Skip to content

tiler: exact early-outs for two sweep-line tests (tile_contours about 6x faster, same results) - #1355

Merged
transfix merged 2 commits into
masterfrom
p3b/tiler-speed
Nov 18, 2026
Merged

transfix merged 2 commits into
masterfrom
p3b/tiler-speed

Conversation

@transfix

@transfix transfix commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

cvc::tile_contours is about 6× faster, with bit-for-bit the same results. The bunny test (#1352) showed tiling at about 0.6 s per slice pair; this finds where that time went and removes most of it.

Where the time went

Timers around each stage, on the Stanford bunny's contours: 50 slices, 95 contours, 9,536 vertices, curation_delta = 0. Windows, MSVC 19.44, Release.

Stage Before After
OTV table (build_OTV_table_steps) 11.9 s 0.28 s
— of which intersects_proper 12.3 s* —
Phase 1 (build_tiling_table_phase1_steps) 4.5 s 1.9 s
— of which test_theorem4 5.5 s* 0.35 s
Everything else (hierarchies, correspondences, tiling regions, phase 2, curation, augmentation) < 0.4 s < 0.4 s

* Measured in runs while the machine was busier, so these exceed their stage totals. Within each run, these calls were nearly all of their stage.

Both hot calls ran a full sweep line over every contour edge, for every candidate:

  • intersects_proper (polygon_utils.cpp) checks each OTV candidate segment against both slices' contours.
  • test_theorem4 (theorems.cpp) checks each tile's two chords against every contour edge.

The change

Each now starts with an exact pass over the same pairs the sweep tests: a bounding-box reject, then the kernel's exact do_intersect, then a check for a shared endpoint. The sweep runs only when that pass can't decide.

Why the pass agrees with the sweep:

  • What the sweep tests: every pair of segments whose x ranges overlap. It reports a pair only when do_intersect holds, and it leaves out a contact at one shared endpoint of each (the end_end case, which these calls filter out).
  • Polygon edges against each other: a simple polygon's edges meet only at shared endpoints, so they report nothing.
  • intersects_proper: if no edge meets the segment except at a shared endpoint off its line, the sweep's point list is empty, so the result is false. Otherwise it runs the original code.
  • test_theorem4: the theorem fails exactly when the sweep reports something; it was already its first test, and the code after it never ran. So it returns false at the first contact the sweep would report (an endpoint inside the other segment, or a crossing), and true when there is none. A chord lying on an edge's line, which touches or overlaps it, still goes to the sweep.
  • Degenerate cases (a zero-length segment or edge) count as collinear, so they go to the sweep too.

A test that assumed the old speed

TilerIntrinsicsAriadne.AnActionStartsItUnderTheDefaultLimits needs the job to span at least two of job_keys' progress notes, which come about every 100 ms. Its tube(30, 96) stack now tiles in about 0.3 s on macOS, which showed one progress value and failed recipe / macos-latest / Release. It now uses tube(60, 192): about 3 s on Windows, with 6–7 progress values.

Checked

  • Same output. On the bunny, the tiled surface is bit-identical before and after: an FNV hash of every vertex coordinate and triangle matches with curation_delta 0 (bd9817f30de78fcb) and 1e-8 (9fffa7c5cafaf9d2).

  • Same tests. These pass, Windows, MSVC 19.44:

    • tiler_test 20/20, including T1's exact legacy parity on the tube and branch triangles;
    • tiler_legacy_test 58/58;
    • tiler_intrinsics_test 9/9;
    • cvc_cli_test Tile* 4/4;
    • pycvc_tiler (now 1.2 s, from 9 s);
    • the bunny test, with the same distances.
  • wasm-mt: tiler_test 20/20 under node 22, with the series embedded.

  • Speed. tile_contours on the bunny, run back to back, two runs each:

    curation_delta before after
    0 16.5 s, 15.4 s 2.65 s, 2.41 s
    1e-8 (the default) 14.9 s, 15.7 s 2.55 s, 2.65 s

    The whole bunny test now takes about 13 s, down from 45–60 s; most of it is now the SDF.

  • Formatting: git-clang-format is clean on the changed lines.

Not checked locally: Linux, macOS and the sanitizer lanes. CI runs these.

Profiling tile_contours on the Stanford bunny's contours (50 slices, 9,536
vertices; tiler_bunny_test) showed two calls taking almost all the time,
each running a full sweep line over every contour edge for each candidate:
- intersects_proper (polygon_utils.cpp), in the OTV table: 12 s of 16.5;
- test_theorem4 (theorems.cpp), in phase 1: 5.5 s of the rest.

Both now start with an exact pass over the same pairs the sweep tests (a
bounding-box reject, then the kernel's do_intersect, then the shared-endpoint
case), and run the sweep only when that pass cannot decide:
- intersects_proper returns false when no edge meets the segment except at
  a shared endpoint off its line: the sweep's points would be empty.
- test_theorem4 returns false at the first contact the sweep would report
  (an endpoint inside the other segment, or a crossing) and true when there
  is none. A chord on an edge's line still goes to the sweep.

The results are bit for bit the same: the tiled bunny hashes identically
before and after, with and without curation; tiler_test (with T1's exact
legacy parity), tiler_legacy_test, tiler_intrinsics_test, cvc tile and
pycvc_tiler pass. tile_contours on the bunny: 15.0-16.5 s before, 2.4-2.65 s
after (Windows, MSVC, Release).
…tiling is faster

AnActionStartsItUnderTheDefaultLimits needs the job to span at least two of job_keys' progress notes, which come about every 100 ms. With the faster tiler, tube(30, 96) finished in about 0.3 s on macOS and 0.5 s on Windows, and showed one progress value (recipe / macos-latest / Release on #1355). tube(60, 192) takes about 3 s on Windows and shows 6-7.
@transfix
transfix merged commit a85bd85 into master Nov 18, 2026
29 of 30 checks passed
@transfix
transfix deleted the p3b/tiler-speed branch November 18, 2026 18:51
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