{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/53340","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/53340/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/53340/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/53340/events","html_url":"https://github.com/rust-lang/rust/issues/53340","id":350367391,"node_id":"MDU6SXNzdWUzNTAzNjczOTE=","number":53340,"title":"Performance regression in tight loop since rust 1.25","user":{"login":"pedrocr","id":246322,"node_id":"MDQ6VXNlcjI0NjMyMg==","avatar_url":"https://avatars3.githubusercontent.com/u/246322?v=4","gravatar_id":"","url":"https://api.github.com/users/pedrocr","html_url":"https://github.com/pedrocr","followers_url":"https://api.github.com/users/pedrocr/followers","following_url":"https://api.github.com/users/pedrocr/following{/other_user}","gists_url":"https://api.github.com/users/pedrocr/gists{/gist_id}","starred_url":"https://api.github.com/users/pedrocr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedrocr/subscriptions","organizations_url":"https://api.github.com/users/pedrocr/orgs","repos_url":"https://api.github.com/users/pedrocr/repos","events_url":"https://api.github.com/users/pedrocr/events{/privacy}","received_events_url":"https://api.github.com/users/pedrocr/received_events","type":"User","site_admin":false},"labels":[{"id":113376,"node_id":"MDU6TGFiZWwxMTMzNzY=","url":"https://api.github.com/repos/rust-lang/rust/labels/I-slow","name":"I-slow","color":"e10c02","default":false},{"id":211668062,"node_id":"MDU6TGFiZWwyMTE2NjgwNjI=","url":"https://api.github.com/repos/rust-lang/rust/labels/T-libs","name":"T-libs","color":"bfd4f2","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2018-08-14T10:22:20Z","updated_at":"2018-12-21T11:37:05Z","closed_at":null,"author_association":"NONE","body":"I've finally gotten around to doing some proper benchmarking of rust versions for my crate:\r\n\r\nhttp://chimper.org/rawloader-rustc-benchmarks/\r\n\r\nAs can be seen in the graph on that page there's a general performance improvement over time but there are some very negative outliers. Most (maybe all) of them seem to be very simple loops that decode packed formats. Since rust 1.25 those are seeing 30-40% degradations in performance. I've extracted a minimal test case that shows the issue:\r\n\r\n```rust\r\nfn decode_12le(buf: &[u8], width: usize, height: usize) -> Vec<u16> {\r\n  let mut out: Vec<u16> = vec![0; width*height];\r\n\r\n  for (row, line) in out.chunks_mut(width).enumerate() {\r\n    let inb = &buf[(row*width*12/8)..];\r\n\r\n    for (o, i) in line.chunks_mut(2).zip(inb.chunks(3)) {\r\n      let g1: u16 = i[0] as u16;\r\n      let g2: u16 = i[1] as u16;\r\n      let g3: u16 = i[2] as u16;\r\n\r\n      o[0] = ((g2 & 0x0f) << 8) | g1;\r\n      o[1] = (g3 << 4) | (g2 >> 4);\r\n    }\r\n  }\r\n  out\r\n}\r\n\r\nfn main() {\r\n  let width = 5000;\r\n  let height = 4000;\r\n\r\n  let buffer: Vec<u8> = vec![0; width*height*12/8];\r\n  \r\n  for _ in 0..100 {\r\n    decode_12le(&buffer, width, height);\r\n  }\r\n}\r\n```\r\n\r\nHere's a test run on my machine:\r\n\r\n```sh\r\n$ rustc +1.24.0 -C opt-level=3 bench_decode.rs \r\n$ time ./bench_decode \r\n\r\nreal\t0m4.817s\r\nuser\t0m3.581s\r\nsys\t0m1.236s\r\n$ rustc +1.25.0 -C opt-level=3 bench_decode.rs \r\n$ time ./bench_decode \r\n\r\nreal\t0m6.263s\r\nuser\t0m5.067s\r\nsys\t0m1.196s\r\n```"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/449366130","html_url":"https://github.com/rust-lang/rust/issues/53340#issuecomment-449366130","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/53340","id":449366130,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0OTM2NjEzMA==","user":{"login":"pedrocr","id":246322,"node_id":"MDQ6VXNlcjI0NjMyMg==","avatar_url":"https://avatars3.githubusercontent.com/u/246322?v=4","gravatar_id":"","url":"https://api.github.com/users/pedrocr","html_url":"https://github.com/pedrocr","followers_url":"https://api.github.com/users/pedrocr/followers","following_url":"https://api.github.com/users/pedrocr/following{/other_user}","gists_url":"https://api.github.com/users/pedrocr/gists{/gist_id}","starred_url":"https://api.github.com/users/pedrocr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedrocr/subscriptions","organizations_url":"https://api.github.com/users/pedrocr/orgs","repos_url":"https://api.github.com/users/pedrocr/repos","events_url":"https://api.github.com/users/pedrocr/events{/privacy}","received_events_url":"https://api.github.com/users/pedrocr/received_events","type":"User","site_admin":false},"created_at":"2018-12-21T11:37:05Z","updated_at":"2018-12-21T11:37:05Z","author_association":"NONE","body":"It either works extremely well or somehow LLVM figured out how to optimize away too much:\r\n\r\n```\r\npacked12le : 1.24.1  BASE 3.46\r\npacked12le : 1.25.0  FAIL 5.00 (+44%)\r\npacked12le : 1.26.2  FAIL 4.87 (+40%)\r\npacked12le : 1.27.2  FAIL 4.91 (+41%)\r\npacked12le : 1.28.0  FAIL 4.83 (+39%)\r\npacked12le : 1.29.2  FAIL 4.99 (+44%)\r\npacked12le : 1.30.1  FAIL 5.01 (+44%)\r\npacked12le : 1.31.0  OK   1.80 (-47%)\r\npacked12le : beta    OK   1.80 (-47%)\r\npacked12le : nightly OK   1.83 (-47%)\r\n```"}}
{"actor":{"display_login":"pedrocr"}}