Repository navigation
tiler: exact early-outs for two sweep-line tests (tile_contours about 6x faster, same results) - #1355
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cvc::tile_contoursis 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.build_OTV_table_steps)intersects_properbuild_tiling_table_phase1_steps)test_theorem4* 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:
do_intersectholds, and it leaves out a contact at one shared endpoint of each (theend_endcase, which these calls filter out).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 isfalse. 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 returnsfalseat the first contact the sweep would report (an endpoint inside the other segment, or a crossing), andtruewhen there is none. A chord lying on an edge's line, which touches or overlaps it, still goes to the sweep.A test that assumed the old speed
TilerIntrinsicsAriadne.AnActionStartsItUnderTheDefaultLimitsneeds the job to span at least two ofjob_keys' progress notes, which come about every 100 ms. Itstube(30, 96)stack now tiles in about 0.3 s on macOS, which showed one progress value and failedrecipe / macos-latest / Release. It now usestube(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_delta0 (bd9817f30de78fcb) and 1e-8 (9fffa7c5cafaf9d2).Same tests. These pass, Windows, MSVC 19.44:
tiler_test20/20, including T1's exact legacy parity on thetubeandbranchtriangles;tiler_legacy_test58/58;tiler_intrinsics_test9/9;cvc_cli_testTile*4/4;pycvc_tiler(now 1.2 s, from 9 s);wasm-mt:
tiler_test20/20 under node 22, with the series embedded.Speed.
tile_contourson the bunny, run back to back, two runs each:curation_deltaThe whole bunny test now takes about 13 s, down from 45–60 s; most of it is now the SDF.
Formatting:
git-clang-formatis clean on the changed lines.Not checked locally: Linux, macOS and the sanitizer lanes. CI runs these.