{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/5117","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/5117/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/5117/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/5117/events","html_url":"https://github.com/JuliaLang/julia/issues/5117","id":24184467,"number":5117,"title":"room for performance improvement for SubArray","user":{"login":"alsam","id":5341924,"avatar_url":"https://avatars.githubusercontent.com/u/5341924?v=3","gravatar_id":"","url":"https://api.github.com/users/alsam","html_url":"https://github.com/alsam","followers_url":"https://api.github.com/users/alsam/followers","following_url":"https://api.github.com/users/alsam/following{/other_user}","gists_url":"https://api.github.com/users/alsam/gists{/gist_id}","starred_url":"https://api.github.com/users/alsam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alsam/subscriptions","organizations_url":"https://api.github.com/users/alsam/orgs","repos_url":"https://api.github.com/users/alsam/repos","events_url":"https://api.github.com/users/alsam/events{/privacy}","received_events_url":"https://api.github.com/users/alsam/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/JuliaLang/julia/labels/performance","name":"performance","color":"d7e102"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":50,"created_at":"2013-12-12T15:12:03Z","updated_at":"2015-06-05T16:20:20Z","closed_at":null,"body":"For the following synthetic testcase:\r\n\r\n```julia\r\n\r\nfunction mykern(r, s, a, x, y)\r\n    const nsteps = 25000 \r\n    istep = 0\r\n    \r\n    ifirst = minimum(r)\r\n    ilast  = maximum(r)\r\n    while istep < nsteps #&& t < tmax\r\n\r\n        for i = ifirst : ilast-1\r\n            s[i] = a * (x[i+1] - x[i]) / (y[i+1] - y[i])\r\n        end\r\n\r\n        for i = ifirst : ilast\r\n            x[i] = a * s[i-1]\r\n        end\r\n\r\n        for i = ifirst : ilast\r\n            y[i] = a * x[i-1]\r\n        end\r\n\r\n        for i = ifirst : ilast-1\r\n            s[i] = s[i] - (x[i+1] - x[i]) / (y[i+1] - y[i])\r\n        end\r\n        istep=istep + 1\r\n    end \r\n    s\r\nend \r\n\r\nconst siz = 10^4\r\nconst a = e^pi - pi^e\r\n\r\ns = rand(siz)\r\nx = rand(siz)\r\ny = rand(siz)\r\n\r\ns1 = sub(s, 1:(siz - 1))\r\nx1 = sub(x, 1:(siz - 1))\r\ny1 = sub(y, 1:(siz - 1))\r\n\r\ns2 = sub(s, 2:siz)\r\nx2 = sub(x, 2:siz)\r\ny2 = sub(y, 2:siz)\r\n\r\ns3 = sub(s, 4:siz)\r\n\r\n# warming up\r\nmykern( 2:(siz - 3), s, a, x,  y  )\r\nmykern( 2:(siz - 3), s, a, x1, y1 )\r\n\r\n# the real test\r\n\r\nprintln(\"follow up: mykern( 2:(siz - 3), s, a, x, y )\")\r\n@time mykern( 2:(siz - 3), s, a, x,  y  )\r\nprintln(\"follow up: mykern( 3:(siz - 2), s2, a, x2, y2 )\")\r\n@time mykern( 3:(siz - 2), s2, a, x2, y2 )\r\n\r\nprintln(\"profiling: mykern( 2:(siz - 3), s, a, x, y )\")\r\n@profile mykern( 2:(siz - 3), s, a, x,  y  )\r\nProfile.print()\r\n#code_typed(mykern,(2:(siz - 3), s, a, x,  y))\r\ncode_llvm(mykern,(2:(siz - 3), s, a, x,  y))\r\ncode_native(mykern,(2:(siz - 3), s, a, x,  y))\r\n\r\nprintln(\"profiling: mykern( 3:(siz - 2), s2, a, x2, y2 )\")\r\n@profile mykern( 3:(siz - 2), s2, a, x2, y2 )\r\nProfile.print()\r\n#code_typed(mykern,(3:(siz - 2), s2, a, x2, y2))\r\ncode_llvm(mykern,(3:(siz - 2), s2, a, x2, y2))\r\ncode_native(mykern,(3:(siz - 2), s2, a, x2, y2))\r\n```\r\n\r\nSubArray based arrays got significant - up to 4x performance slowdown than Array based ones.\r\n\r\nProfiling diff:\r\n\r\n```\r\n-follow up: mykern( 2:(siz - 3), s, a, x, y )\r\n-elapsed time: 2.848171233 seconds (611520 bytes allocated)\r\n-follow up: mykern( 3:(siz - 2), s2, a, x2, y2 )\r\n-elapsed time: 8.839612056 seconds (704324 bytes allocated)\r\n-profiling: mykern( 2:(siz - 3), s, a, x, y )\r\n-2807 boot.jl; include; line: 238\r\n-    2807 profile.jl; anonymous; line: 14\r\n-       98  ...ray/src/shifted3.jl; mykern; line: 10\r\n-       801 ...ray/src/shifted3.jl; mykern; line: 11\r\n-       149 ...ray/src/shifted3.jl; mykern; line: 14\r\n-       344 ...ray/src/shifted3.jl; mykern; line: 15\r\n-       96  ...ray/src/shifted3.jl; mykern; line: 18\r\n-       430 ...ray/src/shifted3.jl; mykern; line: 19\r\n-       889 ...ray/src/shifted3.jl; mykern; line: 23\r\n+profiling: mykern( 3:(siz - 2), s2, a, x2, y2 )\r\n+11591 boot.jl; include; line: 238\r\n+    11591 profile.jl; anonymous; line: 14\r\n+       185  ...ray/src/shifted3.jl; mykern; line: 10\r\n+       3302 ...ray/src/shifted3.jl; mykern; line: 11\r\n+       149  ...ray/src/shifted3.jl; mykern; line: 14\r\n+       2078 ...ray/src/shifted3.jl; mykern; line: 15\r\n+       96   ...ray/src/shifted3.jl; mykern; line: 18\r\n+       2133 ...ray/src/shifted3.jl; mykern; line: 19\r\n+       3648 ...ray/src/shifted3.jl; mykern; line: 23\r\n```\r\n\r\nrevealed that for SubArray code was invoked more frequently, say for the line 11\r\n```julia\r\n            s[i] = a * (x[i+1] - x[i]) / (y[i+1] - y[i])\r\n```\r\n\r\nThe Array version was invoked 801 times, SubArray version - 3301, i.e. 4x time more frequently.\r\n\r\nAny hints for more detailed profiling/study of the code?"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/109350364","html_url":"https://github.com/JuliaLang/julia/issues/5117#issuecomment-109350364","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/5117","id":109350364,"user":{"login":"mbauman","id":154641,"avatar_url":"https://avatars.githubusercontent.com/u/154641?v=3","gravatar_id":"","url":"https://api.github.com/users/mbauman","html_url":"https://github.com/mbauman","followers_url":"https://api.github.com/users/mbauman/followers","following_url":"https://api.github.com/users/mbauman/following{/other_user}","gists_url":"https://api.github.com/users/mbauman/gists{/gist_id}","starred_url":"https://api.github.com/users/mbauman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbauman/subscriptions","organizations_url":"https://api.github.com/users/mbauman/orgs","repos_url":"https://api.github.com/users/mbauman/repos","events_url":"https://api.github.com/users/mbauman/events{/privacy}","received_events_url":"https://api.github.com/users/mbauman/received_events","type":"User","site_admin":false},"created_at":"2015-06-05T16:20:20Z","updated_at":"2015-06-05T16:20:20Z","body":"The culprit seems to be c8b5c0a.  Removing that from master brings my perf tests back to within their expected range."}}