From 6b634075f5b884a607f46fb1796a127d7905c933 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sat, 22 Dec 2018 18:26:20 +0100 Subject: [PATCH] cairo: speed up the cairo append_path() slow path Using the Gtk3Cairo backend with wire3d_animation_sgskip.py: Before: 9.15 fps After: 10.93 fps Converting the code to int makes the comparisons faster. --- lib/matplotlib/backends/backend_cairo.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/backends/backend_cairo.py b/lib/matplotlib/backends/backend_cairo.py index 7d8166451a6c..e3ad7664368c 100644 --- a/lib/matplotlib/backends/backend_cairo.py +++ b/lib/matplotlib/backends/backend_cairo.py @@ -90,6 +90,8 @@ def _append_paths_slow(ctx, paths, transforms, clip=None): for path, transform in zip(paths, transforms): for points, code in path.iter_segments( transform, remove_nans=True, clip=clip): + # int is a lot faster than uint8 when comparing + code = int(code) if code == Path.MOVETO: ctx.move_to(*points) elif code == Path.CLOSEPOLY: