-
Notifications
You must be signed in to change notification settings - Fork 66
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
Early exit for empty index in vec_assign()
#1590
base: main
Are you sure you want to change the base?
Conversation
Yes please, it never hurts to add one more test :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually tempted to put this optimization deep within the assignment macros, like ASSIGN_INDEX()
, ASSIGN_COMPACT()
, the corresponding BARRIER macros, and the corresponding "shaped" ones for arrays. Otherwise I think it is very hard to get the placement of the optimization right, because we aren't always exactly sure what index
is (is it compact, or not?) and we have all kinds of other checks on x
/proxy
/value
that we want to ensure are run before we decide to early exit.
Basically I think the early exit should be done as close to the generation of the copy as possible (i.e. the vec_clone_referenced()
call)
|
||
// Cast and recycle `value` | ||
value = KEEP(vec_cast(value, x, opts.value_arg, opts.x_arg, opts.call)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the cast and recycle checks need to run before we can think about early exiting
Closing for the reasons explained in #1636 (comment) |
Reopening, because I'd like to reconsider in light of tidyverse/tidyr#1392 — the performance gains seem meaningful, and it seems much more reasonable to handle this in vctrs rather than having to wrap every use of |
Closes #1408.
For example this is relevant for
coalesce()
like uses, e.g.vec_assign(x, is.na(x), 1L)
.I only added this optimisation for
vec_assign_opts()
and not for other functions inslice-assign.h
e.g.vec_proxy_assign_opts()
. I only sawvec_proxy_assign_opts()
being called inunchop()
andvec_c()
but it don't think one would encounter an empty index there.Do you want an explicit test that
vec_assign(x, integer(), -1L)
works? It is currently tested "indirectly" viavec_slice(x, FALSE) <- 2L
.Created on 2022-07-15 by the reprex package (v2.0.1)