Making R 300x times faster!

Sdílet
Vložit
  • čas přidán 20. 06. 2024
  • Someone came to me with some slow R code and asked if Rust could make it faster. Here is how I made their R code 300 times faster using Rust. After, someone schools me and makes the code 2000 times faster using base R and data.table. Sometimes an over emphasis on the tidyverse and data frames can make folks write slower code!
    0:00 - Intro
    1:00 - The problem
    1:35 - Reviewing the code
    2:50 - Function break down
    3:50 - Lookup vectors
    4:35 - function rewrite
    5:05 - benchmark lookup vector
    5:20 - function rewrite
    7:50 - Rust R function
    17:15 - Benchmark
    17:25 - a better approach
    18:00 - 3rd circle of hell
    20:45 - R is fast
  • Věda a technologie

Komentáře • 18

  • @semigsedem
    @semigsedem Před rokem +5

    My girlfriend says you are a good presenter even though she does not care for programming. Great video ! :)

  • @NicholasTierney
    @NicholasTierney Před měsícem

    Great video, Josiah!
    For benchmarking, just a fun FYI in case you didn't know, you can do `summary(benchmark_obj, relative = TRUE)` and it will compare the two in relative terms, which is neat!

  • @joshavery
    @joshavery Před rokem +4

    First time of hearing about lookup vectors using the names feature... super smart. Good video!

  • @rpm2508
    @rpm2508 Před rokem +2

    Amazing video!
    I’ve been using R for about 2 years now and I had no idea how fast R could be. Didn’t know how powerfull Vectorization could be.
    Have you ever tought about making a series of videos about Vectorization? Like starting from the more obvious ways one should implement Vectorization in “every-day code”, and go on to more advanced and nuanced examples.
    I’d love to watch that. But thats just an idea.
    Anyway, congratz for the awsome video. I’ve just found your channel, but already subscribed!

  • @pizzaprosciuttofunghi
    @pizzaprosciuttofunghi Před rokem +1

    Thank you so much for these well-made, interesting and inspiring videos of yours!! :)

  • @lukasgroeninger
    @lukasgroeninger Před rokem +2

    Love this video and ur content! ❤

  • @jessapplegate8099
    @jessapplegate8099 Před rokem +1

    this video is awesome! thank you!!!!

  • @shaoru
    @shaoru Před rokem +2

    R is fast; good use of data.table is super fast

  • @olubode
    @olubode Před rokem +2

    So my takeaway is if “Rust go Brrrr”, the “R (can) go!Hmmmm”

    • @josiahparry
      @josiahparry  Před rokem +1

      Definitely! And also, if you know how to use R is goes VROOOOOOMMMMM. It's ungodly fast if you know how to use it right :)

    • @olubode
      @olubode Před rokem

      @@josiahparry I suggested Hmmm as y’a know speed of light :)

  • @user-nq4gg7to4b
    @user-nq4gg7to4b Před rokem +1

    Please share with me your handsome Rstudio theme! Many thanks in advance!

    • @josiahparry
      @josiahparry  Před rokem

      You can get my theme on Github gist.github.com/JosiahParry/082f417c01a87c3a35674bc6fb830f2d

  • @joonasvonlerber
    @joonasvonlerber Před rokem +3

    For summing an entire iterator, you may use .sum(). I don't know if it will work with the extender crate, but worth trying out ;)

    • @josiahparry
      @josiahparry  Před rokem

      Nice! Thats good to know. I don't think it will work with extendr because you need to handle NAs that could come form the R side. I'll ask the discord :)

    • @ilia__k
      @ilia__k Před rokem

      Primitive types like Rint and Rfloat can be sum()-med

    • @josiahparry
      @josiahparry  Před rokem

      @@ilia__k if an NA is present it will result in NA, no?