-
Notifications
You must be signed in to change notification settings - Fork 4
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
More Efficient Cleanup #65
Comments
Thanks for the suggestion. Your comments nudged me to profile library(crew)
library(proffer)
command <- quote(a + b)
data <- list(a = 1)
globals <- list(b = 2)
pprof(
replicate(
1e3,
crew_eval(command = command, data = data, globals = globals)
)
) the flame graph looks like this: So it looks like the bottleneck now is indeed setting and restoring global options. I think relying on |
If you go forward with the bitmask approach for cleanup, I will add logical arguments |
I also wonder if you think there may be a faster/native way to restore the RNG state after each task. Currently I am using |
Implemented in mirai 0.8.2.9019. It's a simple additive bitmask, you simply assign the options values 1,2,4,8 and sum them. I am not entirely sure this works for you as resetting options without unloading packages could be an issue - Nevertheless, it doesn't hurt to offer the flexibility - there is enough of a disclaimer in the docs. |
I've had a look at your use of The default behaviour of |
FYI, be careful when resetting R options. There are cases where removing an option wreaks havoc. For example, in R (< 4.3.0), there were several built-in R options that could not be reset (https://bugs.r-project.org/show_bug.cgi?id=18372). There are also packages out there that rely on their options not being removed, e.g. truecluster/ff#14. This is why I rolled back automatic setting of R options in future a while back (https://github.com/HenrikBengtsson/future/blob/f7c11acb4d2260e882dcd3b392b905c82709d5ae/R/expressions.R#L32-L50) - the risk of breaking things is simply too great. PS. It feels like I've already mentioned this at some point, but in case I just made that memory up, I'm posting this comment. |
Thanks for the note and the examples. Thankfully @shikokuchuo also warned me about this and so Lines 48 to 51 in ace596d
I am not sure built-in base options would be affected because the original state should already have the right values, but maybe I am missing something. From a package development perspective, it seems like good practice to gracefully handle missing options (or not rely on them at all; |
Correct, but only since R 4.3.0. |
Also just to note on this, options cleanup in The implied assumption is that any new options set by packages would be specific to that package - which again isn't enforceable, but should be true in general - any conflict would be no different to if both namespaces were loaded at the same time, so I contend nothing to be done specifically here. Also, it should not run into the R (< 4.3.0) bug as it would not be setting any options to NULL. |
Prework
Description
The initial state is obtained and then reset after each task in your crew evaluation wrapper.
Getting the initial state each time is not required.
More efficient solution is to let mirai get this once per daemon and do the cleanup after each task.
I know I was not keen on being able to pick and choose, but I am prepared to offer flexibility for each of the above through the cleanup argument being an integer number (operating a bitmask). This will make it too obscure for most users rather than drawing attention to different cleanup options, which was my initial concern.
Are the above the only operations you need?
The text was updated successfully, but these errors were encountered: