-
Notifications
You must be signed in to change notification settings - Fork 26
Lazily generate lifecycle stage conditionMessage()
#195
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
Conversation
@@ -1,5 +1,7 @@ | |||
# lifecycle (development version) | |||
|
|||
* The condition generated by `signal_stage()` no longer directly exposes fields such as `cnd$package` and `cnd$function_nm`. |
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 looked around on GitHub and can't find any usage of this
# `cnd_signal()` calls `signalCondition()`, which currently eagerly evaluates | ||
# `conditionMessage()`, meaning that right now we don't save any time by making | ||
# the message generation lazy. But we are hoping to fix this in base R in the | ||
# future, since the message is only used in the error path and could be | ||
# generated on demand at that point. | ||
# https://github.com/wch/r-source/blob/f200c30b1a20dfa9394d7facff616e9cb2a42c6d/src/library/base/R/conditions.R#L157-L163 | ||
# https://github.com/wch/r-source/blob/f200c30b1a20dfa9394d7facff616e9cb2a42c6d/src/main/errors.c#L1904-L1909 | ||
#' @export | ||
conditionMessage.lifecycle_stage <- function(c) { | ||
lifecycle_stage_cnd_data(c)$message | ||
} |
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.
Here is my description of the current issue with signalCondition()
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.
In the interim, do you think it's worth some hack to call .Internal(.signalCondition(cond, msg, call))
directly? Might be interesting to do it, just to see what the performance implication is.
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.
In the last example of #195 (comment) I show using a dummy message of "x"
which roughly simulates the performance implications I think.
Looks like the lazy way would be roughly another 20% faster on top of everything else so far? 36µs
vs 46.2µs
from above.
I'm not sure that's worth the hackery because I'm not sure what we'd put in there for msg
. We could put a dummy message there but if something triggers this weird C branch where the msg
is actually used then users would see it
https://github.com/wch/r-source/blob/f200c30b1a20dfa9394d7facff616e9cb2a42c6d/src/main/errors.c#L1904-L1909
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 going to get everything I have so far merged and do a draft PR with the hackery to take a look at it "for real"
# `cnd_signal()` calls `signalCondition()`, which currently eagerly evaluates | ||
# `conditionMessage()`, meaning that right now we don't save any time by making | ||
# the message generation lazy. But we are hoping to fix this in base R in the | ||
# future, since the message is only used in the error path and could be | ||
# generated on demand at that point. | ||
# https://github.com/wch/r-source/blob/f200c30b1a20dfa9394d7facff616e9cb2a42c6d/src/library/base/R/conditions.R#L157-L163 | ||
# https://github.com/wch/r-source/blob/f200c30b1a20dfa9394d7facff616e9cb2a42c6d/src/main/errors.c#L1904-L1909 | ||
#' @export | ||
conditionMessage.lifecycle_stage <- function(c) { | ||
lifecycle_stage_cnd_data(c)$message | ||
} |
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.
In the interim, do you think it's worth some hack to call .Internal(.signalCondition(cond, msg, call))
directly? Might be interesting to do it, just to see what the performance implication is.
0b44299
to
67e50bf
Compare
Branched from #194
This goes one step beyond #194 and puts us in full control of manual generation of the
lifecycle_stage
condition object.The point is to lazily generate the
conditionMessage()
as needed. Unfortunately this does not currently save us any time because base R'ssignalCondition()
eagerly callsconditionMessage()
too soon (see inline comments). But switching to this is probably still worth it since I'd like to see if Luke would fix this in base R.With #194 alone
This PR with current R (a little faster from switching away from
cnd()
)By putting in a dummy message of
"x"
inconditionMessage.lifecycle_stage()
to simulate what lazy messaging should get us: