Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid vec_assign() call when all rows match #4976

Merged
merged 1 commit into from
Mar 11, 2020

Conversation

DavisVaughan
Copy link
Member

For left and full joins, we can often avoid a vec_assign() call if all rows in x have a match in y. This helps performance in these cases.

These benchmarks are on top of #4975

library(dplyr, warn.conflicts = FALSE)
library(bench)

data_size <- 1000000

left_df <- tibble(
  a = sample(1:7, data_size, TRUE),
  b = sample(c("a","a","b","c","d"), data_size, TRUE)
)

right_df <- tibble(
  b = c("a","b","c", "d"),
  c = 1:4
)

bench::mark(
  left_join = left_join(left_df, right_df, by = "b"),
  check = FALSE,
  iterations = 100
)

# This PR + #4975 
#> # A tibble: 1 x 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 left_join    46.2ms   50.5ms      19.2    58.5MB     158.

# Just #4975 
#> Warning: Some expressions had a GC in every iteration; so filtering is disabled.
#> # A tibble: 1 x 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 left_join    55.7ms   73.9ms      11.8    73.9MB     23.7

Created on 2020-03-11 by the reprex package (v0.3.0)

@DavisVaughan DavisVaughan merged commit e1f32c8 into tidyverse:master Mar 11, 2020
@DavisVaughan DavisVaughan deleted the join-avoid-assign branch March 11, 2020 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants