Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of custom-iterator __getitem__ #1096

Merged
merged 1 commit into from
Feb 20, 2024

Conversation

jakelishman
Copy link
Member

@jakelishman jakelishman commented Feb 20, 2024

Flipping the order of Slice and Int in SliceOrInt so that Int comes first means that the FromPyObject derivation will then try Int first, which is the correct variant in like 99.9% of uses of the struct. This has the impact of improving int __getitem__ times in the custom iterators by about 3x (from 205ns to 61ns on my machine), which has knock-on effects for the implicit iterators Python defines for these classes.

This implements the performance improvement I mentioned in #1090 (comment). I can also look into defining manual Python-space iterators (rather than using the implicit one based on __getitem__), if that's an interesting path - I haven't tried it yet, so I don't know if there's more performance to be had.

Flipping the order of `Slice` and `Int` in `SliceOrInt` so that `Int`
comes first means that the `FromPyObject` derivation will then try `Int`
first, which is the correct variant in like 99.9% of uses of the struct.
This has the impact of improving int `__getitem__` times in the custom
iterators by about 3x (from 205ns to 61ns on my machine), which has
knock-on effects for the implicit iterators Python defines for these
classes.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 7978469504

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 96.568%

Totals Coverage Status
Change from base Build 7967150733: 0.0%
Covered Lines: 16740
Relevant Lines: 17335

💛 - Coveralls

@mtreinish mtreinish added the stable-backport-potential This PR or issue is potentially worth backporting for inclusion in a stable branch label Feb 20, 2024
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for finding this and fixing it

@mtreinish mtreinish merged commit d4f28e3 into Qiskit:main Feb 20, 2024
25 checks passed
mergify bot pushed a commit that referenced this pull request Feb 20, 2024
Flipping the order of `Slice` and `Int` in `SliceOrInt` so that `Int`
comes first means that the `FromPyObject` derivation will then try `Int`
first, which is the correct variant in like 99.9% of uses of the struct.
This has the impact of improving int `__getitem__` times in the custom
iterators by about 3x (from 205ns to 61ns on my machine), which has
knock-on effects for the implicit iterators Python defines for these
classes.

(cherry picked from commit d4f28e3)
@mtreinish
Copy link
Member

@Mergifyio backport stable/0.14

Copy link
Contributor

mergify bot commented Feb 20, 2024

backport stable/0.14

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Feb 20, 2024
Flipping the order of `Slice` and `Int` in `SliceOrInt` so that `Int`
comes first means that the `FromPyObject` derivation will then try `Int`
first, which is the correct variant in like 99.9% of uses of the struct.
This has the impact of improving int `__getitem__` times in the custom
iterators by about 3x (from 205ns to 61ns on my machine), which has
knock-on effects for the implicit iterators Python defines for these
classes.

(cherry picked from commit d4f28e3)
@jakelishman jakelishman deleted the getitem-perf branch February 20, 2024 20:03
@IvanIsCoding
Copy link
Collaborator

Thanks for writing this! I had a feeling we’d need to profile the function but I guess the fix was easier than we thought

mtreinish pushed a commit that referenced this pull request Feb 21, 2024
Flipping the order of `Slice` and `Int` in `SliceOrInt` so that `Int`
comes first means that the `FromPyObject` derivation will then try `Int`
first, which is the correct variant in like 99.9% of uses of the struct.
This has the impact of improving int `__getitem__` times in the custom
iterators by about 3x (from 205ns to 61ns on my machine), which has
knock-on effects for the implicit iterators Python defines for these
classes.

(cherry picked from commit d4f28e3)

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
mtreinish added a commit to mtreinish/retworkx that referenced this pull request Feb 22, 2024
This commit prepares for a 0.14.1 release which just includes Qiskit#1109 to
fix ppc64le builds and Qiskit#1096 to fix the overhead of `__getitem__` on
custom sequence return types.
mtreinish added a commit that referenced this pull request Feb 22, 2024
* Prepare 0.14.1 release

This commit prepares for a 0.14.1 release which just includes #1109 to
fix ppc64le builds and #1096 to fix the overhead of `__getitem__` on
custom sequence return types.

* Update releasenotes/notes/prepare-0.14.1-e5065553a44eb035.yaml

Co-authored-by: Ivan Carvalho <8753214+IvanIsCoding@users.noreply.github.com>

* Update version in docs config too

---------

Co-authored-by: Ivan Carvalho <8753214+IvanIsCoding@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stable-backport-potential This PR or issue is potentially worth backporting for inclusion in a stable branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants