Skip to content

Commit

Permalink
MNT: Add cache for creating interpolator
Browse files Browse the repository at this point in the history
It is slow to create an interpolator and there are a lot of calls to
project, so keep the interpolator around to speed up repeated calls.
  • Loading branch information
greglucas committed Aug 22, 2021
1 parent 60c5b38 commit e763573
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/cartopy/trace.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ In general, this should never be called manually, instead leaving the
processing to be done by the :class:`cartopy.crs.Projection` subclasses.
"""
from __future__ import print_function
from functools import lru_cache

cimport cython
from libc.math cimport HUGE_VAL, sqrt
Expand Down Expand Up @@ -559,6 +560,7 @@ cdef void _project_segment(GEOSContextHandle_t handle,
lines.new_line()


@lru_cache(maxsize=4)
def _interpolator(src_crs, dest_projection):
# Get an Interpolator from the given CRS and projection.
# Callers must hold a reference to these systems for the lifetime
Expand Down

0 comments on commit e763573

Please sign in to comment.