Turbocharged: Writing High-Performance C# and .NET Code - Steve Gordon

Поділитися
Вставка
  • Опубліковано 1 сер 2024
  • In this session, you'll learn how to write C# code which executes faster and allocates less. This session is packed with practical examples and demos of where the latest high-performance APIs and language features can be applied in your applications.
    During this session, we'll apply types such as Span and Memory to efficiently process data and to parse strings. We'll examine System.IO.Pipelines, offering high-performance I/O and we'll utilise ArrayPool to help reduce GC allocations. In .NET Core 3.0, we have new high-performance JSON APIs which we'll also add to our arsenal. Microsoft has made fantastic performance gains to the .NET Core framework; now it's time to apply them to your code!
    We'll begin by discussing when and why performance matters in your applications. You'll learn how to measure your code, and use a data-driven approach to focus your optimisations.
    These features can seem complicated, unapproachable and difficult to apply. In this session, Steve introduces high-performance newcomers to the features, showing you how they work, where they can be applied and how to measure performance improvements in your code.
    This talk is for developers, who like Steve, are ready to begin their journey towards writing faster .NET code, which allocates less.
    Check out more of our talks, courses, and conferences in the following links:
    ndcconferences.com/
    ndc-london.com/
  • Наука та технологія

КОМЕНТАРІ • 59

  • @ahives
    @ahives 4 роки тому +11

    This is a great talk. I just gave an internal talk on Performance Engineering where I went over BenchmarkDotNet and how I use it to optimize certain algorithms. I also went over the role of microbenchmarking on refactoring designs to be more performant. Needless to say, this talk went over really well. I got this notification on UA-cam after I gave my talk so I decided to distribute it internally. Again, excellent talk.

  • @clearlyunwell
    @clearlyunwell 4 роки тому +6

    Excellent, thank you!

  • @kevinlettier5273
    @kevinlettier5273 4 роки тому +1

    Great talk, very informative.
    The optimized code is really different from the original one and it seems that when you start through that way you cannot easily come back, so to use with care as you mentioned and on critical path.
    I would love to see on next talk how you can conciliate self documenting approach of the original code and the performance of the optimized one, maybe by decoupling the concrete processing from the orchestration flow ?

  • @joechang8696
    @joechang8696 4 роки тому +5

    What I would like is for certain objects, typically larger ones, to get an virtual address of some granular size, and allocate from its own set of pages. On dispose, both the VAS and memory pages can be easily recycled. To a degree, this would be like SQL Server, which makes extensive use of 8KB pages. This make it difficult to handle large objects. Hence, for C# at 64-bit, we would like to allocate large chunks of VAS, memory in regular (4K), large pages (2M) or even huge.

  • @MrMichaeljosiah
    @MrMichaeljosiah 4 роки тому +4

    Really good presentation. Very informative

  • @elerius2
    @elerius2 4 роки тому +5

    29:30 Spans in async methods. They should improve the compiler to allow span in async so long as the usage of the span doesn't overlap an async operation. I understand the workaround isn't that difficult, but it "feels bad" to factor the usage out into a separate method. Even if it required introducing an explicit scope to contain the span, it would be an improvement.

    • @philipmrch8326
      @philipmrch8326 4 роки тому +1

      I agree, I've thought about this solution too.

  • @odee2004
    @odee2004 4 роки тому +1

    How did they get the "not equal" and "less than equal" using only one text/char in Visual studio? @33:25

    • @neutralenull
      @neutralenull 3 роки тому +1

      Using a different font like firacode

  • @Adiounys
    @Adiounys 4 роки тому +4

    31:45 - is testing index before replacing really faster? It seem like it's searching for the space twice.

    • @default632
      @default632 4 роки тому +1

      Test

    • @Adiounys
      @Adiounys 4 роки тому +2

      @@default632 Well I just did. Here are my results 00:00:04.4693173 replace
      00:00:06.2901262 indexReplace
      00:00:01.6881407 replace[NoSpace]
      00:00:01.6519704 indexReplace[NoSpace]
      00:00:09.3153027 Replace[LastSpace]
      00:00:09.2847721 indexReplace[LastSpace]
      00:00:09.3679662 Replace[FirstSpace]
      00:00:09.3879821 indexReplace[FirstSpace]
      00:00:10.1380442 Replace[long]
      00:00:10.0772212 indexReplace[long]
      And here are input strings I used:
      testedMethods = new List{
      ("replace", ()=>replaceTest("ab cd")),
      ("indexReplace", ()=>indexReplaceTest("ab cd")),
      ("replace[NoSpace]", ()=>indexReplaceTest("abcd")),
      ("indexReplace[NoSpace]", ()=>indexReplaceTest("abcd")),
      ("Replace[LastSpace]", ()=>indexReplaceTest("Soiqpbiosdssdadsatoeigsdawdqdsadqwcx ")),
      ("indexReplace[LastSpace]", ()=>indexReplaceTest("Soiqpbiosdssdadsatoeigsdawdqdsadqwcx ")),
      ("Replace[FirstSpace]", ()=>indexReplaceTest(" Soiqpbiosdssdadsatoeigsdawdqdsadqwcx")),
      ("indexReplace[FirstSpace]", ()=>indexReplaceTest(" Soiqpbiosdssdadsatoeigsdawdqdsadqwcx")),
      ("Replace[long]", ()=>indexReplaceTest("Soiqpbiosdssdadsat oeigsdawdqdsadqwcx")),
      ("indexReplace[long]", ()=>indexReplaceTest("Soiqpbiosdssdadsat oeigsdawdqdsadqwcx")),
      };

  • @axedaddy1
    @axedaddy1 3 роки тому

    And we get all this functionality for three.

  • @Geoters
    @Geoters 4 роки тому +1

    At 34:39 code line 117 has c != ' ' but it looks much different. What kind of sorcery is that and how can i do it??

    • @WilliamSandersAu
      @WilliamSandersAu 4 роки тому +3

      Had a quick look into this, apparently you have to install a font into Visual Studio that supports ligatures (e.g. Fira Code).

    • @Roy192
      @Roy192 4 роки тому

      There's also a version of consolas that has ligatures: github.com/somq/consolas-ligaturized
      Just remember to restart visual studio after changing the font.

    • @GeorgeTsiros
      @GeorgeTsiros 3 роки тому

      @@WilliamSandersAu screw fira code. go with ubuntu mono ligaturized

  • @karldavis7392
    @karldavis7392 Рік тому

    I try to group questions asked of the user together. Let's say I have five questions, and need five seconds of processing to handle each. If I ask all five questions back-to-back, then do 25 seconds of processing, the user feels it's faster, because they can go do something else instead of waiting for the app.

  • @slavimo
    @slavimo 3 роки тому +1

    Instead of String.Join() you could have use StringBuilder instead to get rid of those allocations. So the comparison of String.Join vs StringBuilder vs Span is lacking in your example, IMO.

  • @GordonGEICO
    @GordonGEICO 3 роки тому +1

    "... you'll end up with a StackOverflowException and then you'll end up on Stack Overflow trying to work out why."
    Which will, inevitably, lead to your question getting closed for being a duplicate, even though none of the links to the (completely unnecessary) third party libraries work because the projects were abandoned long ago.

    • @GeorgeTsiros
      @GeorgeTsiros 3 роки тому

      SO is a disaster. The SNR is too low.

  • @focl2003
    @focl2003 4 роки тому +2

    What is the font he's using?

    • @ayoubihbibibi2404
      @ayoubihbibibi2404 4 роки тому

      Same question !!!!!

    • @focl2003
      @focl2003 4 роки тому

      @@Flynnor thank you, I'll check it out.

    • @Adiounys
      @Adiounys 4 роки тому

      I know Codist can make similar looks marketplace.visualstudio.com/items?itemName=wmj.Codist

    • @jr.BoarOfGold
      @jr.BoarOfGold 4 роки тому +1

      He's using Fira Code

  • @lollo4711
    @lollo4711 4 роки тому +6

    since every cpu-tick counts (money) on cloud computing/hosting those aspects really come (back) into consideration (for years I lost overview/interest how 'fast' my code (really) runs and how much it consumes [on fat clients])

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Blow

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Wellekey

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    ASME blow

  • @mottahh4162
    @mottahh4162 4 роки тому

    wouldn't using a span with strings, if we changed the original string the span will also be changed, also, a slice of a span will be effected by the changes done on the original span

    • @dongbinrabbit
      @dongbinrabbit 4 роки тому +8

      strings are immutable and strings can only be converted to readonly spans.

    • @CodeWithSteve
      @CodeWithSteve 4 роки тому +1

      @@dongbinrabbit Yep exactly!

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Allo

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Baelley

  • @CarrotCakeMake
    @CarrotCakeMake 4 роки тому

    So it is a slice in Rust.

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Below

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Ettay konney

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Kofeley

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Gotta

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Kemey

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Jegna

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Hubbeny

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Wanna Eye

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Kemey me ziarikey

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Eweniy

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Kemey ke

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Sllestiom nattey

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Nattey

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Ewe

  • @minnedanhieux883
    @minnedanhieux883 4 місяці тому

    Nice talk... but comming from c++... meh.

  • @Esico6
    @Esico6 4 роки тому +3

    .net is pretty fast out of the box but if you want performance dont use it. .net will work against you. It can be done but too much workarounds and .net GC tuning.
    Never use linq on areas where u need perf.

    • @hichamo-sfh177
      @hichamo-sfh177 4 роки тому +2

      I don't think so
      Because linq still highly performance than using a loop and if statements ..

    • @ahives
      @ahives 4 роки тому +3

      Hmm. Just curious, have you ever built critical healthcare systems that operate at scale before? I co-maintain the most performant healthcare parser in the world that executes in nanoseconds/microseconds and it uses LINQ and other functional programming concepts. In my experience your statement is not valid. If you are curious, here it is github.com/MassTransit/Machete.

    •  4 роки тому +1

      .net is pretty fast out of the box but if you want performance dont use it

    •  4 роки тому

      @@hichamo-sfh177 Take a look : github.com/microsoft/referencesource/blob/master/System.Core/System/Linq/Enumerable.cs
      Why do you think it is faster than loop and if statements if they are just that?

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Sellestiom

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Baelley

  • @belowasmelashgebremariam
    @belowasmelashgebremariam 2 роки тому

    Reay