My Rust Program is Slow

Поделиться
HTML-код
  • Опубликовано: 13 дек 2024

Комментарии • 47

  • @Veliladon
    @Veliladon 2 года назад +111

    I know I've asked this question on your previous video about the release flag so thank you for the follow up video!

    • @chrisbiscardi
      @chrisbiscardi  2 года назад +25

      Your question definitely made this video happen :)

  • @drmonkeys852
    @drmonkeys852 2 года назад +18

    Compiler optimizations are the coolest thing. Like if you look at the assembly generated from the optimization level 0 it's basically doing what you'd expect doing a loop which adds all the numbers, but the optimized version figures out hey we're only ever going to be returning the same result every time we do this cause the bounds are constants so it figures out the answer compile time and makes the assembly return it.

  • @ziiirozone
    @ziiirozone 2 года назад +67

    Interesting, I’m new to rust so I wasn’t even aware that there was multiple profiles and what they actually meant, thanks Chris !

    • @CapnSlipp
      @CapnSlipp 2 года назад +4

      The bigger lesson to be learned is that this is true of almost every programming language- it started in the C days and continued in nearly every compiled language and also applies to most interpreted programming languages. And the reason why different profiles/build-types/build-levels/optimization settings matter is indicated by that last term in that list; a compiler can make optimizations to instructions that make them more performant in the CPU’s machine code, and sometimes even skip human-organizational clutter (e.g. inlining functions) when it knows that line-by-line debugging isn’t required.
      A small introductory dip into compiler design will teach you how syntax is lexxed into symbols, and that’s constructed into an abstract syntax tree, which can be reasoned upon and simplified (like a crazier version of middle-school algebra) before finally being spit out as CPU-specific machine instructions or an assembly-like intermediary language (IL) for interpreted languages. You really don’t need a CS degree and the ability to write your own compiler to understand the basics- making sure every chunk of CPU instructions are correlated with each line of original source code is a heck of a lot slower than what a compiler (which knows a lot more about how CPUs run instructions and handle memory than most programmers) can rearrange and combine and flatten your code into.

  • @ruchdaneabiodun
    @ruchdaneabiodun 2 года назад +29

    i didn't search for this but thanks
    I've recently started learning rust and this is good to know

  • @Myrkvi_
    @Myrkvi_ 2 года назад +5

    Hi! Great video, and it's great that you added subtitles! As they currently are, though, it's a bit too long and messy and looks more like a written paragraph; this might make it a bit difficult to follow along for those reading the subtitles.

    • @chrisbiscardi
      @chrisbiscardi  2 года назад

      yup, I've since fixed the subtitle generation on the channel but haven't gotten to redoing the back catalogue yet. thanks for the reminder.

    • @chrisbiscardi
      @chrisbiscardi  2 года назад

      I've updated the captions for this video

    • @Myrkvi_
      @Myrkvi_ 2 года назад

      @@chrisbiscardi thanks! it's a lot easier to follow along now :)

  • @BohdanTrotsenko
    @BohdanTrotsenko 2 года назад +7

    Wow! While I knew about release, I watched the video to the end just "for a checkmark", but it happened to fill a knowledge gap. Thank you!

  • @simdimdim
    @simdimdim 2 года назад +11

    This audio is.... in need of some filtering

    • @chrisbiscardi
      @chrisbiscardi  2 года назад +9

      not much I can do about having been sick and losing my voice earlier this week.

    • @simdimdim
      @simdimdim 2 года назад +16

      @@chrisbiscardi no, no, if it was just being sick I would've only wished you to get healthy quickly, it's fading in and out, there's static, the frequencies feel clipped. I'd recommend you redo the audio once you're feeling better and reupload a remuxed version (also wishes for being healthy again soon, cheers). (Otherwise nice info, did not know it's possible to granularly control profiles per crate)

    • @samueldiker
      @samueldiker 2 года назад +2

      @@simdimdim Maibe the recording level is too high, it was loud and not pleasant on my speakers.
      But it is interesting, I had this problem once :D

  • @jocketf3083
    @jocketf3083 2 года назад +4

    The algorithm recommended this video to me, and it sure was an informative one. Thank You!

  • @annguyenhoangphu451
    @annguyenhoangphu451 2 года назад +9

    Thank for your video.
    How about build for WASM. Does it have release mode too?

    • @chrisbiscardi
      @chrisbiscardi  2 года назад +9

      wasm is a compilation target for the rust compiler (like wasm32-unknown-unknown), so the profiles still apply.
      There are a bunch of additional optimizations you can make when targeting wasm to, for example, reduce the wasm binary size. More info here: rustwasm.github.io/docs/book/reference/code-size.html

  • @rotteegher39
    @rotteegher39 Год назад

    Bevy dynamic feature has changed.
    bevy = {version = "0.10.0", features = ["dynamic_linking"]}

  • @zun1777
    @zun1777 2 года назад +6

    tbh people should at least notice that something is wrong when they look at the binary filesize (it's how i learned that there is a release flag)

    • @chrisbiscardi
      @chrisbiscardi  2 года назад +7

      for many people, using Rust is their first time using a compiled language, so they don't have that context for how big a binary should be yet

    • @zun1777
      @zun1777 2 года назад

      @@chrisbiscardi that's true ig

  • @youtubepooppismo5284
    @youtubepooppismo5284 2 года назад +6

    Goddamit I love rust

  • @Garush
    @Garush 2 года назад

    Thanks for the informative video!!

  • @vlknckl
    @vlknckl 2 года назад +2

    Thank you Chris

  • @farresalt4381
    @farresalt4381 2 года назад

    I never heard of Rust or your channel before. What are you?
    ...
    Nice voice. Almost perfect. That saliva-range noises being removed would've probably made it inescapable for most people like me, who randomly got your videos recommended. Good video still, but could be improved.
    Only to make more people interested in the topic, of course, because those who know about it would watch you anyway, but still.

  • @LukasTheWizard
    @LukasTheWizard 2 года назад

    your website doesnt work

  • @gwentarinokripperinolkjdsf683
    @gwentarinokripperinolkjdsf683 2 года назад

    I actually am making a game and I always compile in O3

  • @aydnbilgin1627
    @aydnbilgin1627 2 года назад

    I have no problem using soft soft, I just dont understand the tools and such, ofc it takes a long "#"¤ ti to make sotNice tutorialng because of

  • @CortlandMahoney
    @CortlandMahoney 6 месяцев назад

    woah!! Adding this
    ```
    [profile.dev]
    opt-level = 1
    [profile.dev.package."*"]
    opt-level = 3
    ```
    to my cargo.toml file was an instant ~5x speed boost while running tests. Thank you much much!

  • @berksedatk
    @berksedatk 2 года назад

    maybe its just a lil *rust*y

  • @zlandauer
    @zlandauer 2 года назад +1

    why does my programming language need a package manager and profiles

    • @zun1777
      @zun1777 2 года назад +6

      i mean no one is forcing you to use cargo

    • @notusingmyrealnamegoogle6232
      @notusingmyrealnamegoogle6232 2 года назад +12

      because they’re useful (and optional)

    • @adamkoxxl
      @adamkoxxl 2 года назад +12

      Why would anyone choose to not use these tools when they're provided? C is horrible in this regard.

    • @notusingmyrealnamegoogle6232
      @notusingmyrealnamegoogle6232 2 года назад +10

      “why does my programming language need a pre-made compiler when I can implement the spec myself”

    • @tentaklaus9382
      @tentaklaus9382 2 года назад +3

      "Why can't I make things more difficult for myself!?"

  • @LoganDark4357
    @LoganDark4357 2 года назад +1

    YOU'RE SO LOUD HOLY MOLY

    • @erandom2635
      @erandom2635 2 года назад

      ... You can change the volume on your end

    • @LoganDark4357
      @LoganDark4357 2 года назад +1

      @@erandom2635 I believe you misunderstood the point of my comment

  • @snesmocha
    @snesmocha 2 года назад +3

    but that's literally just 03 optimizations...?

    • @NabekenProG87
      @NabekenProG87 2 года назад +12

      Yes and? Thats the whole point, showing how to use optimization in Rust

    • @snesmocha
      @snesmocha 2 года назад

      @@NabekenProG87 isn't there directly an 03 flag in rust? also how do people not know such a basic feature.... idk it feels like pointing out the obvious...

    • @glugt9240
      @glugt9240 2 года назад +15

      @@snesmocha Not everyone has been programming for years, people may get started with rust or come from languages like java

    • @not_ever
      @not_ever 2 года назад +6

      You'd be surprised how many people don't understand compiler optimisations, especially people who use IDEs that hide all this information behind a debug/release dropdown menu.

    • @pehdfms8621
      @pehdfms8621 2 года назад +1

      @@diadetediotedio6918 I think this discussion is completely out of topic for this video, but I do think IDEs hide a bit TOO much to the point where working around one feels like black magic. Doesn't help much then that IDE skills are generally not easy to transfer between IDEs (key exception being JetBrains' products). if I need to change a compiler configuration, I want to google "how to change compiler configuration in language x", not "how to change compiler configuration in language x in IDE y", especially if the language x in question is even somewhat obscure.

  • @gg-gn3re
    @gg-gn3re 2 года назад

    Go has this too, with -ldflags="-s -w" (these remove the debug crap)