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

Improve performance of enframe #353

Closed
hadley opened this issue Jan 4, 2018 · 2 comments
Closed

Improve performance of enframe #353

hadley opened this issue Jan 4, 2018 · 2 comments

Comments

@hadley
Copy link
Member

@hadley hadley commented Jan 4, 2018

By using lower level constructor.

library(tibble)
options(digits = 3)

enframe2 <- function(x, name = "name", value = "value") {
  if (rlang::is_null(names(x))) {
    l <- list(seq_along(x), x)
  } else {
    l <- list(names(x), unname(x))
  }
  names(l) <- c(name, value)
  new_tibble(l)
}

x <- setNames(letters, letters)

microbenchmark::microbenchmark(
  enframe(x),
  enframe2(x)
)
#> Unit: microseconds
#>         expr    min     lq mean median     uq   max neval cld
#>   enframe(x) 1066.2 1116.9 1792 1185.7 1270.3 39110   100   b
#>  enframe2(x)   77.9   85.2  157   89.9   97.2  4283   100  a

(This is with dev rlang so I'm a little surprised that the speed difference is still so huge - it's probably worth a little profiling of data_frame)

@krlmlr
Copy link
Member

@krlmlr krlmlr commented Jan 4, 2018

Will add this to #348.

@krlmlr krlmlr closed this in bd6af96 Jan 15, 2018
krlmlr added a commit that referenced this issue Jan 15, 2018
- Faster construction and subsetting for tibbles (#353).
krlmlr added a commit that referenced this issue Jan 20, 2018
- `enframe(NULL)` now returns the same as `enframe(logical())` (#352).
- `tbl[1, , drop = TRUE]` now behaves identically to data frames (#367).
- The `tibble.width` option is honored again (#369).
- Faster printing of very wide tibbles (#360).
- Update vignette to match changes in 1.4.1 (#368, @bgreenwell).
- Don't rely on `ncol()` for `glimpse()`, only query `nrow()` and `head()`.
- Return input for zero-column data frames.
- Add test for `glimpse()` with unknown rows (#366, @kevinykuo).
- Faster construction and subsetting for tibbles (#353).
- `tribble()` now ignores trailing commas (#342, @LaDilettante).
- Fix error message when accessing columns using a logical index vector (#337, @mundl).
krlmlr added a commit that referenced this issue Jan 23, 2018
Bug fixes
---------

- Fix OS X builds.
- The `tibble.width` option is honored again (#369).
- `tbl[1, , drop = TRUE]` now behaves identically to data frames (#367).
- Fix error message when accessing columns using a logical index vector (#337, @mundl).
- `glimpse()` returns its input for zero-column data frames.

Features
--------

- `enframe(NULL)` now returns the same as `enframe(logical())` (#352).
- `tribble()` now ignores trailing commas (#342, @LaDilettante).
- Updated vignettes and website documentation.

Performance
-----------

- Faster printing of very wide tibbles (#360).
- Faster construction and subsetting for tibbles (#353).
- Only call `nrow()` and `head()` in `glimpse()`, not `ncol()`.
@github-actions
Copy link

@github-actions github-actions bot commented Dec 11, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants