-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
matplotlib.path.contains_points is a LOT slower in 1.51 #6444
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
Comments
attn @mdboom Exactly which version of 1.4.x were you using? refactored the code a bit to remove unittest overhead import numpy as np
import math
import matplotlib
from matplotlib.path import Path
print(matplotlib.__version__)
def get_polygon_path(polygon_x, polygon_y):
vertices = list(zip(polygon_x, polygon_y))
p = Path(vertices, None, closed=True, readonly=True)
return p
def get_in_polygon(x1, x2, y1, y2, path):
x, y = np.meshgrid(np.arange(x1, x2), np.arange(y1, y2))
x, y = x.flatten(), y.flatten()
pts = np.vstack((x, y)).T
# Find points that belong to snake in minimal rectangle
path.contains_points(pts)
def test_matplotlib():
for k in range(10):
angles = np.linspace(0, 2 * math.pi, 90)
px = 150 + 100 * np.cos(angles)
py = 150 + 100 * np.sin(angles)
poly = get_polygon_path(px, py)
get_in_polygon(50, 250, 50, 250, poly) I see # 1.5.1.post1832+g76a884c
In [39]: %timeit test_matplotlib()
1 loop, best of 3: 487 ms per loop # 1.4.3
In [4]: %timeit test_matplotlib()
10 loops, best of 3: 147 ms per loop so definitely a slow down, but not 30x |
I use the 1.4.0 version. |
Can you also test 1.4.3 and current master? On Wed, May 18, 2016 at 6:38 PM Fafa87 notifications@github.com wrote:
|
This is like the first time that I play with virtualenv but these are my results: -- End pasted text --1.4.0 -- End pasted text --1.4.3 -- End pasted text --1.5.1 I did not manage to build master (freetype, png failed). |
so a factor of ~5x |
I bisected 1.4.0 to 1.4.3 (about 1.6x slower for me):
Haven't done the 1.4.3->1.5.1 bisection yet. Master runs about the same speed as 1.5.1. |
Comparing Internally there is one other change, going from a malloced int array to a |
I've noticed that you use Python 3.5.1 and I am stuck on Python 2.7.8 (should have mentioned that in the begining). |
Here are some remaining bisections for additional performance drops. Apparently, the C++ stdlib/STL is not very performant... For me, 1.4.0 runs in ~0.059s; there is an increase to ~0.096s at:
There is another increase to ~0.195s between dbeed94 and d8c1d0d (this is the CXX removal, I believe.) Performance varies a little up to ~0.216-0.220s around 6c33b0d, but then jumps to ~0.291s due to:
Finally, there is another jump to ~0.335s at:
Using the proposed changes from #6446 (which mostly address the first commit) drops runtime to ~0.160s. |
All these tests were run with 3.5.1, but as all the changes appear to originate in the C++ code, I don't think it really makes a difference if you are using 2.7.8. |
I've checked on Python 3.4.1 then I get to your x5: My Python2 also x64 (2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)]). |
The cause of this jump seems to be from d7cc9eb (runtime of ~0.214s), but that is a merge commit. The parents are e2061f7 and c31ffe8, which have runtimes of ~0.193s and ~0.092s, respectively. If I understood the diffs correctly, the left side is the CXX changes, and the right side contains 4b63f75, so this one would probably have been covered by #6446? Using the new #6450, the runtime is ~0.158s, so about the same as #6446. |
@Fafa87 Can you try out the v1.5.x branch? |
Building matplotlib on windows turned out not to be that easy. Thanks for the quick work! |
Hi!
I have a code using matplotlib.path to create a mask of points inside a polygon. Lately we moved from version 1.4 to 1.51 and at first I thought that our program started to hang but it turned out that it just took about 30x more time to create masks.
Profiler showed that the problem is with path.contains_points(pts).
I've extracted the problem to a unit test and did tests 1.4 vs 1.51:
1.4 - 70 ms
1.51 - 2215 ms
Am I doing or setting something wrong or is it indeed a problem with a new version?
Regards
Filip Mróz
The text was updated successfully, but these errors were encountered: