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

Improve getPoints() + explode() performance for large geometries #1

Merged
merged 1 commit into from
Apr 20, 2016

Conversation

babldev
Copy link

@babldev babldev commented Apr 20, 2016

Issue
For geometries with 10k+ points, it can take 10+ seconds on a modern machine to call getPoints() or pointInPolygon().

Root Cause
The points array was built using array_merge(), which gets more complex (n^2) as the array gets larger.

Fix
Use simple array appending instead of array_merge()

Before:

$ time ../vendor/bin/phpunit tests/largeInputTest.php 
real    0m13.354s
user    0m13.318s
sys 0m0.030s

After:

$ time ../vendor/bin/phpunit tests/largeInputTest.php 
real    0m0.194s
user    0m0.172s
sys 0m0.016s

@babldev
Copy link
Author

babldev commented Apr 20, 2016

Tests passed here phayes#127

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@babldev babldev force-pushed the remove-array-merge branch from ae5be7a to 3d16d79 Compare April 20, 2016 02:01
@danielhochman
Copy link

+1

@babldev babldev merged commit e1a5f77 into master Apr 20, 2016
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.

None yet

2 participants