-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[SR-7759] Swift 4.1.1 performance regression #50298
Comments
cc @moiseev, @eeckstein |
woodcrust (JIRA User) a few questions: did you compile with or without optimizations, as in, what were the compiler command line arguments? Also, do you mind invoking both compilers with `-emit-sil` option and attach the output to the jira? It would help diagnose the issue quicker. |
Comment by Oleh (JIRA) yes of course. Wait please a few minutes ... |
Can confirm that, and it regressed a bit further with Swift 4.2: (the
attaching the sil files too |
Comment by Oleh (JIRA) I attached files with names: latest test on Linux cybertron 3.16.0-4-amd64 #1 SMP Debian 3.16.51-3 (2017-12-13) x86_64 GNU/Linux 4.1.1 - 2,27 sec |
It's possible that the introduction of exclusivity checking for globals is impacting things here. If I change it so that the benchmark code is wrapped in a function, like this: func shellsSort<T : Comparable>(_ arr: inout [T]) {
let n = arr.count
var gap = n/2
var i = 0
var j = 0
var temp : T
while gap > 0 {
i = gap
while i < n {
temp = arr[i]
j = i
while (j >= gap && arr[j - gap] > temp) {
arr[j] = arr[j - gap]
j = j - gap
}
arr[j] = temp
i = i + 1
}
gap = gap/2
}
}
func main() {
var a = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
var c = 0
while (c < 10000000) {
shellsSort(&a)
a = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
c = c + 1
}
}
main() Then I see a 35% improvement, putting it back in line with the Swift 4 performance: $ time ./with_function
real 0m1.469s
user 0m1.451s
sys 0m0.011s
$ time ./with_toplevel_code
real 0m1.982s
user 0m1.960s
sys 0m0.013s We've seen a number of issues where "toplevel" code doesn't get optimized as well as standalone functions do. A lot of this is down to the underlying design flaw that top-level variables are treated like global variables and made visible to functions in other files, meaning we have to optimize them conservatively as if they can be modified from anywhere, when they should really be treated as local to the scope of the implicit toplevel entry point. |
Comment by Oleh (JIRA) ✔ cool thanks a lot, its work 😃 |
Attachment: Download
Additional Detail from JIRA
md5: 4069bbc8d4757d9becf5310fc5d09c1f
Issue Description:
Hello, my name is Oleh. My english is very bad =(
I am seeing a decline in performance between versions like 4.0.3 and 4.1.1. Me very interested, why ? I am testing this on linux os and other computers with this code:
And I see what the regression of performance in 4.1.1 version equal ~74% then in versions 4.0.3, 3.0.1 etc
for example
4.0.3 - 1,66 sec
4.1.1 - 2,89 sec
Please tell me why ?
The text was updated successfully, but these errors were encountered: