Skip to content

Compare polygon contours byte-wise - #2513

Closed
nikosavola wants to merge 2 commits into
KLayout:masterfrom
nikosavola:pr-contour-memcmp
Closed

nikosavola wants to merge 2 commits into
KLayout:masterfrom
nikosavola:pr-contour-memcmp

Conversation

@nikosavola

Copy link
Copy Markdown
Contributor

polygon_contour::operator== compared the points one by one through the tagged-pointer iterator, which never vectorizes. Shape repository insertion and deduplication pay for it on every contour they compare.

Uncompressed contours store the logical points one to one, so for integer coordinates equal bytes mean equal points and memcmp gives the same verdict at SIMD speed. Compressed contours, which reconstruct every second point on access, and floating point coordinates (NaN, negative zero) keep the point-by-point comparison. The rectilinear and hole tag bits live in the pointer, not in the array, and a static_assert pins the point size, so they cannot leak into the compared bytes.

Measured with this change alone, g++ -O2 on a Xeon Gold 6248, repository deduplication:

case before ms after ms speedup
shape_repository_dedup/100000 30.3 26.2 1.16x
shape_repository_dedup/1000000 302 258 1.17x
shape_repository_dedup_large/20000/256 75.9 58.3 1.30x
shape_repository_dedup_large/20000/4096 890 688 1.29x
shape_repository_dedup_large/20000/65536 13470 10360 1.30x

The benchmark is not part of this PR.

- Uncompressed contours store the logical points 1:1, so for integer coordinates equal bytes mean equal points and memcmp gives the same verdict at SIMD speed
- Compressed contours, which reconstruct every second point on access, keep the point-by-point comparison, and so do floating point coordinates (NaN, negative zero)
- The rectilinear and hole tag bits live in the pointer, so they do not leak into the bytes
@nikosavola nikosavola closed this Oct 19, 2026
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