PERF: fast paths for CRS equality and hashing - #1617
Open
greglucas wants to merge 2 commits into
Open
Conversation
greglucas
commented
Aug 9, 2026
Comparing two CRS objects goes through PROJ's proj_is_equivalent_to, which short-circuits on matching identifiers (EPSG codes) but otherwise falls through to a full recursive structural comparison of the datum, ellipsoid, prime meridian, coordinate system and conversion. For CRS built from PROJ strings, which carry no identifier, that costs 11-15us per comparison.
greglucas
force-pushed
the
perf-crs-comparison
branch
from
August 9, 2026 20:09
b1d1dd7 to
31aa45d
Compare
snowman2
reviewed
Aug 10, 2026
snowman2
reviewed
Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Comparing two CRS objects goes through PROJ's proj_is_equivalent_to, which short-circuits on matching identifiers (EPSG codes) but otherwise falls through to a full recursive structural comparison of the datum, ellipsoid, prime meridian, coordinate system and conversion. For CRS built from PROJ strings, which carry no identifier, that costs 11-15us per comparison.
Noticed this in Cartopy where we do a check to see if
self == src_crsto try and speed up transforms, but the CRS comparison itself can be slow.https://github.com/SciTools/cartopy/blob/bdb6cc45e27ff4fe71741b445ac15449aee35ba3/lib/cartopy/crs.py#L410
The short circuits are the simple portion
is selfandsrs1 == srs2, but the problem is that in missing cases we will still fall back to PROJ comparisons which is why I added the cache portion here which is really to speed up the != comparisons.history.rstfor all changes andapi/*.rstfor new API