-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Optimize CxxIterator
and CxxSequence
#61577
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
Conversation
@swift-ci please smoke test |
@swift-ci please benchmark |
Code size: -Osize
Performance (x86_64): -Onone
Code size: -swiftlibs |
These two benchmarks should not be affected by the change, since they use raw C++ iterators. I'm not sure why the results have changed:
|
@swift-ci please benchmark |
1. Instead of storing the C++ collection within `class CxxIterator`, store a boxed C++ collection and make `CxxIterator` a struct. This enables a number of Swift optimizations for iterators, while preserving the guarantee that the C++ collection is not copied or moved in memory (which would invalidate iterators). 2. Make `sequence` parameter shared. This avoids a second copy of the C++ collection when initializing `CxxIterator`. Credits to Alex Lorenz for this idea!
Performance (x86_64): -O
Code size: -O
Performance (x86_64): -Osize
Code size: -Osize
Performance (x86_64): -Onone
Code size: -swiftlibs |
b8ab3d1
to
10b7057
Compare
@swift-ci please smoke test |
@swift-ci please benchmark |
@swift-ci please smoke test Windows |
It's just noise. Any benchmark under 100us is going to be mostly noise (maybe these ones are helpful to establish a baseline though). |
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.
This is awesome, thanks Egor!
Performance (x86_64): -O
Code size: -O
Performance (x86_64): -Osize
Code size: -Osize
Performance (x86_64): -Onone
Code size: -swiftlibs |
300x improvement, that's what I like to see! 😎 |
class CxxIterator
, store a boxed C++ collection and makeCxxIterator
a struct. This enables a number of Swift optimizations for iterators, while preserving the guarantee that the C++ collection is not copied or moved in memory (which would invalidate iterators).sequence
parameter shared. This avoids a second copy of the C++ collection when initializingCxxIterator
.Credits to Alex Lorenz for this idea!