You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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".
publicstructRT {
publicinit() {
data = CxxData(x: 0, y: 0,
m: (0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0))
}
publicfunccall_that_copies() -> Double {
vardata_copy = datareturnanalyze(&data_copy)
}
// exactly the same as above, just that "mutating" was added:publicmutatingfuncmutating_call_that_copies() -> Double {
vardata_copy = datareturnanalyze(&data_copy)
}
vardata: CxxData
}
The structure CxxData is a struct defined in C (i.e. in a bridging header file), as follows:
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.
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
md5: 8aedc273abb245bdbe0dd29efebd0a34
Issue 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:
The text was updated successfully, but these errors were encountered: