{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/10093","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/10093/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/10093/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/10093/events","html_url":"https://github.com/JuliaLang/julia/issues/10093","id":56729127,"number":10093,"title":"Performance issue with sub?","user":{"login":"IainNZ","id":692635,"avatar_url":"https://avatars.githubusercontent.com/u/692635?v=3","gravatar_id":"","url":"https://api.github.com/users/IainNZ","html_url":"https://github.com/IainNZ","followers_url":"https://api.github.com/users/IainNZ/followers","following_url":"https://api.github.com/users/IainNZ/following{/other_user}","gists_url":"https://api.github.com/users/IainNZ/gists{/gist_id}","starred_url":"https://api.github.com/users/IainNZ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IainNZ/subscriptions","organizations_url":"https://api.github.com/users/IainNZ/orgs","repos_url":"https://api.github.com/users/IainNZ/repos","events_url":"https://api.github.com/users/IainNZ/events{/privacy}","received_events_url":"https://api.github.com/users/IainNZ/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":1,"created_at":"2015-02-05T21:01:46Z","updated_at":"2015-02-05T21:48:11Z","closed_at":null,"body":"So some discussion of `sub` came up on [StackOverflow](http://stackoverflow.com/questions/28271308/avoid-memory-allocation-when-indexing-an-array-in-julia/28271440) and, if I'm following correctly, @timholy found the following performance results surprising:\r\n\r\n```\r\nJulia Version 0.4.0-dev+3145\r\nCommit 030e30c (2015-02-05 06:46 UTC)\r\nPlatform Info:\r\n  System: Linux (x86_64-unknown-linux-gnu)\r\n  CPU: Intel(R) Xeon(R) CPU E5-2650 0 @ 2.00GHz\r\n  WORD_SIZE: 64\r\n  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)\r\n  LAPACK: libopenblas\r\n  LIBM: libopenlibm\r\n  LLVM: libLLVM-3.3\r\n```\r\n\r\n```julia\r\nN = 10000000\r\nx = randn(N)\r\ninds = [1:N]\r\ngc()\r\n@time mean(x)\r\ngc()\r\n@time mean(x)\r\ngc()\r\n@time mean(x)\r\ngc()\r\n@time mean(x[inds])\r\ngc()\r\n@time mean(x[inds])\r\ngc()\r\n@time mean(x[inds])\r\ngc()\r\nxs = sub(x, inds)\r\n@time mean(xs)\r\ngc()\r\n@time mean(xs)\r\ngc()\r\n@time mean(xs)\r\ngc()\r\n```\r\n\r\n```\r\nelapsed time: 0.033390763 seconds (986 kB allocated)\r\nelapsed time: 0.007460507 seconds (96 bytes allocated)\r\nelapsed time: 0.007424041 seconds (96 bytes allocated)\r\nelapsed time: 0.182705254 seconds (76 MB allocated, 0.11% gc time in 1 pauses with 0 full sweep)\r\nelapsed time: 0.204156668 seconds (76 MB allocated, 0.10% gc time in 1 pauses with 0 full sweep)\r\nelapsed time: 0.220835177 seconds (76 MB allocated, 0.09% gc time in 1 pauses with 0 full sweep)\r\nelapsed time: 0.258093627 seconds (4 MB allocated)\r\nelapsed time: 0.084950758 seconds (96 bytes allocated)\r\nelapsed time: 0.080124649 seconds (96 bytes allocated)\r\n```"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/73136030","html_url":"https://github.com/JuliaLang/julia/issues/10093#issuecomment-73136030","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/10093","id":73136030,"user":{"login":"simonster","id":470884,"avatar_url":"https://avatars.githubusercontent.com/u/470884?v=3","gravatar_id":"","url":"https://api.github.com/users/simonster","html_url":"https://github.com/simonster","followers_url":"https://api.github.com/users/simonster/followers","following_url":"https://api.github.com/users/simonster/following{/other_user}","gists_url":"https://api.github.com/users/simonster/gists{/gist_id}","starred_url":"https://api.github.com/users/simonster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonster/subscriptions","organizations_url":"https://api.github.com/users/simonster/orgs","repos_url":"https://api.github.com/users/simonster/repos","events_url":"https://api.github.com/users/simonster/events{/privacy}","received_events_url":"https://api.github.com/users/simonster/received_events","type":"User","site_admin":false},"created_at":"2015-02-05T21:48:11Z","updated_at":"2015-02-05T21:48:11Z","body":"Looks like the problem may be that `getindex` isn't inlined for that SubArray."}}