question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Shapely 1.7.a2 and newer versions slow down

See original GitHub issue

Hi, I’m working on a project using Shapely (currently 1.6.4.post2), and I tried to update my version of Shapely. However, I noticed a huge performance decrease using the most recent release.

After a quick investigation, I noticed this problem appears for all version of Shapely >= 1.7a2.

Steps to reproduce the problem.

Example :

from shapely.geometry import Polygon
import shapely
import time

p1 = Polygon([[0,0],[5,0],[5,5],[0,5]])
p2 = Polygon([[0,0],[5,0],[5,5],[0,5]])

t1 = time.time()

for i in range(10000):
	p1.difference(p2)
	
print('Execution time :',time.time()-t1,'seconds')

This small piece of code runs in ~0.6 second on my computer using older versions (<=1.7a1). Using 1.7a2 and newer versions of Shapely, this same code runs in 2.6 seconds.

Operating system

Fedora 30

Shapely version and provenance

Versions >= 1.6.4.post2 installed with pip. I’m using python 3.7.5.

This might be related to #834

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
sgilliescommented, Mar 1, 2020

I’ve tested some new wheels that incorporate these changes to the GEOS build https://github.com/shapely/shapely-wheels/commit/df1f48c8eaf677d7a5af5a47a414e1d71bb44eec and see this:

$ python -m timeit -n 10000 -r 3 -s "from shapely.geometry import Polygon" -s "p1 = Polygon([[0,0],[5,0],[5,5],[0,5]])" -s"p2 = Polygon([[0,0],[5,0],[5,5],[0,5]])" "p1.difference(p2)"
10000 loops, best of 3: 61.8 usec per loop

I’m going to close this issue. There’s no performance regression in Shapely that I can see. If there is one in GEOS related to simple polygon differences, it only seems to occur in unoptimized builds.

When we publish wheels for shapely 1.7.1, users can expect some performance boosts.

1reaction
dbastoncommented, Feb 27, 2020

That said, the optimization focus is usually towards improved performance of expensive operations. Possible that newer versions are slower when taking the difference of two squares.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Shapely 1.7.a2 and newer versions slow down #847 - GitHub
I see a 50% slowdown. The wheels for 1.6.4.post2 include GEOS 3.6.2. The wheels for 1.7.0 include GEOS 3.8.0. It is possible that...
Read more >
Fix for Shapely's GEOS library loading bug in 1.7a2
This changes everything. The problem that has bedeviled shapely users is caused by using dlopen to load a library that's already been loaded....
Read more >
The Shapely User Manual — Shapely 2.0.0 documentation
This document explains how to use the Shapely Python package for ... New in Shapely 1.7.1 ... The individual coordinates are copied into...
Read more >
Shapely Documentation - Read the Docs
Shapely is a BSD-licensed Python package for manipulation and analysis of planar geometric objects. It is using the widely deployed ...
Read more >
The Shapely User Manual - Projects
Abstract: This document explains how to use the Shapely Python package for computational geometry. Introduction ... New in version 1.2.14.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found