{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/16122","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/16122/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/16122/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/16122/events","html_url":"https://github.com/JuliaLang/julia/issues/16122","id":151888191,"number":16122,"title":"Inference: slow for for loop, fast for corresponding while","user":{"login":"timholy","id":1525481,"avatar_url":"https://avatars.githubusercontent.com/u/1525481?v=3","gravatar_id":"","url":"https://api.github.com/users/timholy","html_url":"https://github.com/timholy","followers_url":"https://api.github.com/users/timholy/followers","following_url":"https://api.github.com/users/timholy/following{/other_user}","gists_url":"https://api.github.com/users/timholy/gists{/gist_id}","starred_url":"https://api.github.com/users/timholy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timholy/subscriptions","organizations_url":"https://api.github.com/users/timholy/orgs","repos_url":"https://api.github.com/users/timholy/repos","events_url":"https://api.github.com/users/timholy/events{/privacy}","received_events_url":"https://api.github.com/users/timholy/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-04-29T15:00:46Z","updated_at":"2016-05-03T23:16:12Z","closed_at":"2016-05-03T01:46:49Z","body":"```jl\r\nPkg.clone(\"https://github.com/timholy/ArrayIteration.jl.git\")\r\nPkg.checkout(\"ArrayIteration\", \"teh/stored\")\r\n\r\nusing ArrayIteration\r\n\r\nA = Int[1 3; 2 4]\r\nB = Array{Int}(2, 2)\r\n\r\njulia> @time include(\"/tmp/slow1.jl\")\r\n 23.763574 seconds (31.16 M allocations: 1.095 GB, 2.28% gc time)\r\n```\r\nwhere `slow1.jl` is defined as\r\n```jl\r\nfor (I, a) in sync(index(B, :, 2), value(A, :, 1))\r\n    B[I] = a\r\nend\r\n```\r\nIn contrast, in a fresh session\r\n```jl\r\njulia> @time include(\"/tmp/slow2.jl\")\r\n  0.219750 seconds (130.95 k allocations: 5.498 MB)\r\n```\r\nwhere `slow2` is the manually-expanded while loop version,\r\n```jl\r\niter = sync(index(B, :, 2), value(A, :, 1))\r\ns = start(iter)\r\nwhile !done(iter, s)\r\n    (I, a), s = next(iter, s)\r\n    B[I] = a\r\nend\r\n```\r\n\r\n```jl\r\njulia> versioninfo()\r\nJulia Version 0.5.0-dev+3780\r\nCommit 811fe45* (2016-04-28 09:02 UTC)\r\nPlatform Info:\r\n  System: Linux (x86_64-linux-gnu)\r\n  CPU: Intel(R) Core(TM) i7 CPU       L 640  @ 2.13GHz\r\n  WORD_SIZE: 64\r\n  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Nehalem)\r\n  LAPACK: libopenblas64_\r\n  LIBM: libopenlibm\r\n  LLVM: libLLVM-3.7.1 (ORCJIT, westmere)\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/216693093","html_url":"https://github.com/JuliaLang/julia/issues/16122#issuecomment-216693093","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/16122","id":216693093,"user":{"login":"timholy","id":1525481,"avatar_url":"https://avatars.githubusercontent.com/u/1525481?v=3","gravatar_id":"","url":"https://api.github.com/users/timholy","html_url":"https://github.com/timholy","followers_url":"https://api.github.com/users/timholy/followers","following_url":"https://api.github.com/users/timholy/following{/other_user}","gists_url":"https://api.github.com/users/timholy/gists{/gist_id}","starred_url":"https://api.github.com/users/timholy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timholy/subscriptions","organizations_url":"https://api.github.com/users/timholy/orgs","repos_url":"https://api.github.com/users/timholy/repos","events_url":"https://api.github.com/users/timholy/events{/privacy}","received_events_url":"https://api.github.com/users/timholy/received_events","type":"User","site_admin":false},"created_at":"2016-05-03T23:16:12Z","updated_at":"2016-05-03T23:16:12Z","body":"With regards to closing: perhaps it's worth emphasizing that this is a 2x2 matrix, and that 30 seconds is quite a long time to wait for looping over all of its elements. Since compilation is fast when it's in a function, it's also not an inescapable compilation overhead. In other words, this is likely not your run-of-the-mill \"avoid globals, put it in a function\" problem.\r\n\r\nOK to reopen?"}}