Skip to content

Optimization of valid index calculation #498

Open
@eendebakpt

Description

@eendebakpt

In listobject.c there is an optimization to check whether an index is valid (e.g. 0 <= index < N) using a single comparison.
The same optimization is not used in other files such as tupleobject.c (except for _collectionsmodule.c)

  • Is there a reason the optimization is used only for the list and not a tuple?
  • Would a PR applying this optimization be acceptable? (either only for the tuple, or for all locations where we can do this)

I created a branch with the idea for the tupleobject.c since that might be the most performance critical:

python/cpython@main...eendebakpt:cpython:list_tuple

I could not measure significant performance improvements on my system, but perhaps there are other systems/compilers where there is a measurable difference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions