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

feature suggestion: option to save stashed objects to memory #39

Open
vorpalvorpal opened this issue May 1, 2023 · 2 comments
Open

Comments

@vorpalvorpal
Copy link

I have a large dataframe that is built by doing computationally expensive joins of other dataframes. I have a function that returns this dataframe that looks like this:

data_df <- function(options){
    df <-  
       mustashe::stash(
      "stash_dataDF", 
      {df <- data.frame() # lots of expensive joins here}, 
      depends_on = c(getOption("DFs")),
      functional = TRUE) 
    if (missing(options)) return(df)
   else {
       # do some post-processing of df based on options
       return(df)
    }
}

When I run this and it looks up stash_dataDF and finds that it can load the stashed object, it then has to load stash_dataDF.qs from disk. In my case, this tends to take between 0.25 - 0.5 seconds. Which isn't much, but does add up if data_df() is called multiple times within a larger workflow. I wonder if it would be possible to add an option to save stash_dataDF as an in-memory object and then use the same hash checking as is currently done. stash_dataDF would still need to either be built fresh or loaded from stash_dataDF.qs at the beginning of each session, but then after that, this should be a lot faster than reading it from disk each time.

@jhrcook
Copy link
Owner

jhrcook commented May 26, 2023

This is an interesting idea, I just don't have the time to implement it. A pull request is welcome though!

@DarwinAwardWinner
Copy link

As an alternative, you could consider implementing support for cachem, which supports both disk and memory-backed key-value stores, plus additional features such as pruning of old values.

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

No branches or pull requests

3 participants