{"action":"created","issue":{"url":"https://api.github.com/repos/hadley/dplyr/issues/1299","labels_url":"https://api.github.com/repos/hadley/dplyr/issues/1299/labels{/name}","comments_url":"https://api.github.com/repos/hadley/dplyr/issues/1299/comments","events_url":"https://api.github.com/repos/hadley/dplyr/issues/1299/events","html_url":"https://github.com/hadley/dplyr/issues/1299","id":98818630,"number":1299,"title":"dev version 0.4.2.9002: some functions much slower on factored data ","user":{"login":"daattali","id":952340,"avatar_url":"https://avatars.githubusercontent.com/u/952340?v=3","gravatar_id":"","url":"https://api.github.com/users/daattali","html_url":"https://github.com/daattali","followers_url":"https://api.github.com/users/daattali/followers","following_url":"https://api.github.com/users/daattali/following{/other_user}","gists_url":"https://api.github.com/users/daattali/gists{/gist_id}","starred_url":"https://api.github.com/users/daattali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daattali/subscriptions","organizations_url":"https://api.github.com/users/daattali/orgs","repos_url":"https://api.github.com/users/daattali/repos","events_url":"https://api.github.com/users/daattali/events{/privacy}","received_events_url":"https://api.github.com/users/daattali/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-08-03T19:10:21Z","updated_at":"2015-08-06T19:26:00Z","closed_at":"2015-08-05T16:07:39Z","body":"Followup from #1298 \r\n\r\nTwo examples:\r\n\r\n### `arrange_`\r\n\r\nRunning the following code on dev version:\r\n\r\n```\r\nfactoreddf <- data.frame(x = 1:1e6, y = \"a\")\r\nnonfactoreddf <- data.frame(x = 1:1e6, y = \"a\", stringsAsFactors = FALSE)\r\nfactored <- function() dplyr::arrange_(factoreddf, ~ x)\r\nnonfactored <- function() dplyr::arrange_(nonfactoreddf, ~ x)\r\nmicrobenchmark::microbenchmark(factored(), nonfactored(), times = 10)\r\n```\r\n\r\nProduces these results:\r\n\r\n```\r\nUnit: milliseconds\r\n          expr       min        lq      mean    median       uq       max neval\r\n    factored()  137.1338  137.2456  174.2336  149.0118  180.579  349.3572    10\r\n nonfactored() 2094.7260 2114.0007 2162.2075 2135.4139 2188.226 2300.9723    10\r\n```\r\n\r\nWhile using the CRAN version, both datasets run equally fast\r\n\r\n### `filter_`\r\n\r\nRunning the following code on dev version\r\n\r\n```\r\nfactoreddf <- data.frame(x = rep(letters, 10000))\r\nnonfactoreddf <- data.frame(x = rep(letters, 10000), stringsAsFactors = FALSE)\r\nfactored <- function() dplyr::filter_(factoreddf, ~ x == \"d\")\r\nnonfactored <- function() dplyr::filter_(nonfactoreddf, ~ x == \"d\")\r\nmicrobenchmark::microbenchmark(factored(), nonfactored(), times = 10)\r\n```\r\n\r\nGives these results\r\n\r\n```\r\nUnit: milliseconds\r\n          expr        min         lq       mean     median         uq       max neval\r\n    factored()   18.12856   18.51892   45.89027   19.67587   25.64279  243.4634    10\r\n nonfactored() 1409.14734 1449.10019 1477.18425 1456.73940 1496.66659 1608.2936    10\r\n```\r\n\r\nWhile on CRAN version, nonfactored is actually faster"},"comment":{"url":"https://api.github.com/repos/hadley/dplyr/issues/comments/128480450","html_url":"https://github.com/hadley/dplyr/issues/1299#issuecomment-128480450","issue_url":"https://api.github.com/repos/hadley/dplyr/issues/1299","id":128480450,"user":{"login":"daattali","id":952340,"avatar_url":"https://avatars.githubusercontent.com/u/952340?v=3","gravatar_id":"","url":"https://api.github.com/users/daattali","html_url":"https://github.com/daattali","followers_url":"https://api.github.com/users/daattali/followers","following_url":"https://api.github.com/users/daattali/following{/other_user}","gists_url":"https://api.github.com/users/daattali/gists{/gist_id}","starred_url":"https://api.github.com/users/daattali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daattali/subscriptions","organizations_url":"https://api.github.com/users/daattali/orgs","repos_url":"https://api.github.com/users/daattali/repos","events_url":"https://api.github.com/users/daattali/events{/privacy}","received_events_url":"https://api.github.com/users/daattali/received_events","type":"User","site_admin":false},"created_at":"2015-08-06T19:26:00Z","updated_at":"2015-08-06T19:26:00Z","body":"Ok, my app is *still* extremely slow :(\r\n\r\nFirst issue found:  `arrange_` (possibly other functions as well) is now fixed on the previous sample dataset, but if you try to arrange by a character instead of a numeric variable, we're back to a huge performance regression.\r\n\r\n```\r\nfactoreddf <- data.frame(x = rep(letters, times = 10000))\r\nnonfactoreddf <- data.frame(x = rep(letters, times = 10000), stringsAsFactors = FALSE)\r\nfactored <- function() dplyr::arrange_(factoreddf, ~ x)\r\nnonfactored <- function() dplyr::arrange_(nonfactoreddf, ~ x)\r\nmicrobenchmark::microbenchmark(factored(), nonfactored(), times = 10)\r\n```\r\n\r\n(this time `x` is a character column instead of a numeric column)"}}