-
Notifications
You must be signed in to change notification settings - Fork 269
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
chore(Python): Improve slicing performance #6042
base: master
Are you sure you want to change the base?
chore(Python): Improve slicing performance #6042
Conversation
(I think I'm missing permissions to add #2313 as an issue linked on the PR) |
Thanks for the contribution!
AFAIK you can just say phrases like "Resolves #2313" to make that link happen. But in this case we shouldn't anyway, since that issue is tracking a more general cross-backend improvement, and this change is just improving things for Python. |
Cool, thanks! I made these changes as part debugging performance issues in Crypto Tools products. Now, I'm running into more performance "hiccups", and might need to make more changes. |
I'd say if the additional changes are small and somewhat related, feel free to add them here. Otherwise getting this merged and working on a new PR is probably better. |
I added my changes here because my new changes conflicted with the previous changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is great! Do you have data on the impact of _SeqSlice
as well?
Co-authored-by: Fabio Madge <[email protected]>
Co-authored-by: Fabio Madge <[email protected]>
Co-authored-by: Fabio Madge <[email protected]>
Thanks Fabio, updated the code. I also updated the performance test code and results for the latest implementation. |
What was changed?
Add a new class
Slice
. This is a lazy slice forSeq
s. The elements of aSeq
are immutable, so slices of aSeq
can refer to the originalSeq
's elements, and lazily calculate access based on the slice indices. Before, a slice of aSeq
would copy all elements by value from the original to the newSeq
.Seq
now takes constant time.Slice
takes constant time.Slice
takes constant time.Slice
takes constant time.Slice
takes linear time.How has this been tested?
No new functional testing. I hope that existing tests would catch any issues, but let me know if there are any doubts.
I ran a slicing performance test locally.
Results from my local:
TestNum = 10000, Python before change: 9s
TestNum = 10000, Python after change: <1s
TestNum = 10000, .NET: ~1s
TestNum = 1000000, Python before change: at least 10 minutes
TestNum = 1000000, Python after change: ~1s
I don't plan committing the performance test file, since there's no functional testing there, but let me know if I should.
(I have separate testing in Crypto Tools' Python DBESDK (JSON encryption library) that brings a particular test execution from ~15 minutes to ~30 seconds.)
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.