, 7 tweets, 2 min read
My Authors
Read all threads
Cut an #rstats scripts runtime from 2+ hours to <5 minutes and feel extremely powerful (even though arguably the first version was just bad code)

Don’t know who needs this but a few random tips below. Easy once you’ve heard them but often outside of intro content 👇🏻
Run iterations in parallel! If you’re using {purrr} this is *ridiculously* easy with @dvaughan32 ‘s {furrr}

You truly just add ‘future_’ prefixes to map functions
Remove anything from the iteration that can be done outside including data preprocessing (eg type conversion) or post processing (eg normalizing everything by the same constant)
When possible, use simpler data structures like matrices or vectors versus dataframes
Similarly, use simpler data types. In my ex, I was subsetting of a ton of 0/1 indicators in each iteration. Order of magnitude improvement converting to logical (TRUE / FALSE). Intuitively, give R the benefit of knowing there are only two possible value
Finally make friends with a benchmarking pkg to test out optimization ideas to make sure you’re actually moving in the right direction. My current favorite is {bench}
Obviously this is not close to comprehensive or systematic — just some of the lowest hanging fruit. To generate more ideas and identify bottlenecks in your code, code profilers life {profvis} or @wmlandau ‘s {proffer} are great tools
Missing some Tweet in this thread? You can try to force a refresh.

Enjoying this thread?

Keep Current with Emily Riederer

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!