Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeometryCollection: Cache flags to avoid O(n) lookups #1220

Merged
merged 3 commits into from
Jan 12, 2025

Conversation

dbaston
Copy link
Member

@dbaston dbaston commented Jan 4, 2025

As discussed in locationtech/jts#1100. For a collection with 1 million elements, reduces CoverageUnion runtime by 98%.

Increases the size of collections from 88 to 96 bytes. This could be avoided by storing the flags in Geometry (which has 4 spare bytes) rather than GeometryCollection (which has none).

This PR:

----------------------------------------------------------------------------------
Benchmark                                        Time             CPU   Iterations
----------------------------------------------------------------------------------
BM_CoverageUnion<SegmentSet>/1000          1309915 ns      1309904 ns          544
BM_CoverageUnion<SegmentSet>/4096          5467171 ns      5466976 ns          124
BM_CoverageUnion<SegmentSet>/32768        54011812 ns     54009415 ns           12
BM_CoverageUnion<SegmentSet>/262144      498335728 ns    498323707 ns            2
BM_CoverageUnion<SegmentSet>/1000000    2130948900 ns   2130788554 ns            1
BM_CoverageUnion<BoundaryChain>/1000        866139 ns       866082 ns          745
BM_CoverageUnion<BoundaryChain>/4096       3223064 ns      3222934 ns          216
BM_CoverageUnion<BoundaryChain>/32768     27829346 ns     27825710 ns           25
BM_CoverageUnion<BoundaryChain>/262144   222791662 ns    222777788 ns            3
BM_CoverageUnion<BoundaryChain>/1000000  976485195 ns    976432682 ns            1

main:

----------------------------------------------------------------------------------
Benchmark                                        Time             CPU   Iterations
----------------------------------------------------------------------------------
BM_CoverageUnion<SegmentSet>/1000          1204288 ns      1204243 ns          587
BM_CoverageUnion<SegmentSet>/4096          5243907 ns      5243915 ns          130
BM_CoverageUnion<SegmentSet>/32768        51261928 ns     51258943 ns           13
BM_CoverageUnion<SegmentSet>/262144      477953902 ns    477906954 ns            2
BM_CoverageUnion<SegmentSet>/1000000    2052768394 ns   2052653441 ns            1
BM_CoverageUnion<BoundaryChain>/1000        989152 ns       989121 ns          723
BM_CoverageUnion<BoundaryChain>/4096       5400333 ns      5399829 ns          123
BM_CoverageUnion<BoundaryChain>/32768    109018236 ns    109002983 ns            6
BM_CoverageUnion<BoundaryChain>/262144  5086413577 ns   5085701992 ns            1
BM_CoverageUnion<BoundaryChain>/1000000 3.7859e+10 ns   3.7757e+10 ns            1

@dr-jts dr-jts added the Enhancement New feature or feature improvement. label Jan 4, 2025
@dr-jts
Copy link
Contributor

dr-jts commented Jan 4, 2025

Increases the size of collections from 88 to 96 bytes.

Seems like a low-percentage increase.

@rouault rouault self-requested a review January 8, 2025 02:23
@rouault rouault merged commit 1660b79 into libgeos:main Jan 12, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or feature improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants