Open swift-ci opened 5 years ago
cc @eeckstein. Maybe we're not eliminating the copy in the non-mutating case? Although that's only safe if we really do believe the const
in the C function declaration…but I think we do elsewhere.
Comment by David Baraff (JIRA)
My assembly-fu is weak, but when I last looked, my impression was that one path used memcpy, the other did the same copy inline (copying each variable as a separate line) and one path happened to be faster than the other.
Don't hold me to the above, though, I could easily have misread what I was reading. Assembly is not my thing...
Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Improvement, Performance | |Assignee | None | |Priority | Medium | md5: 8aedc273abb245bdbe0dd29efebd0a34Issue Description:
In the code below, the mutating function call is faster by almost 2x than the non-mutating version. To see this, just call both functions about 25 million times. If you'd like an Xcode project which packages all this up as library and executable which runs the timing, please do " git clone git@github.com:davidbaraff/ptrTest2.git".
The structure CxxData is a struct defined in C (i.e. in a bridging header file), as follows:
while the function "analyze()" is written in C, and returns a constant value: