diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index 01c43486f800f..604fd9256e10f 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -153,7 +153,7 @@ Deprecations Performance improvements ~~~~~~~~~~~~~~~~~~~~~~~~ -- +- Performance improvement when indexing with more than 4 keys (:issue:`54550`) - .. --------------------------------------------------------------------------- diff --git a/pandas/_libs/index.pyx b/pandas/_libs/index.pyx index e974b5d0eec46..5c7680bc6fb6c 100644 --- a/pandas/_libs/index.pyx +++ b/pandas/_libs/index.pyx @@ -375,7 +375,7 @@ cdef class IndexEngine: # map each starget to its position in the index if ( stargets and - len(stargets) < 5 and + len(stargets) < (n / (2 * n.bit_length())) and not na_in_stargets and self.is_monotonic_increasing ):