grattan / covidReff

Simulating Covid reproduction in a partially vaccinated population
Other
4 stars 1 forks source link

Performance remarks #22

Closed HughParsonage closed 3 years ago

HughParsonage commented 3 years ago

I'll just put down random thoughts.

Consider

# The defaults for these options can make performance better, but
# occasionally worse. Try:
options(datatable.auto.index = FALSE)
options(datatable.use.index = FALSE)
# instead of
sum(newly_infected & vaccine_dose == 2L)

# consider (may be faster, may be slower)
library(hutilscpp)
sum_and3s(newly_infected, vaccine_dose == 2L)
HughParsonage commented 3 years ago

If something is type integer ensure this is preserved (i.e. not coerced to double). For example,


 aus[is_vaccinated == TRUE,
        days_since_first_dose := 1000] %>%
      .[is_vaccinated == FALSE,
        days_since_first_dose := 0] 

# better
 aus[is_vaccinated == TRUE,
        days_since_first_dose := 1000L] %>%
      .[is_vaccinated == FALSE,
        days_since_first_dose := 0L] 

# best
aus[, days_since_first_dose  := fifelse(is_vaccinated, 1000L, 0L)]
``
wfmackey commented 3 years ago

Thanks Hugh. I'll play around and see if there are any significant improvements with options or sum_and3s.

I have changed to aus[, days_since_first_dose := fifelse(is_vaccinated, 1000L, 0L)] (my standard practice!) in #23.