@lexi_lambda: How to make a Haskell program 5x faster with 16 lines of code

Поділитися
Вставка
  • Опубліковано 27 сер 2024
  • Alexis has "had the opportunity for the past couple months at Tweag to work on optimizing the compile time performance of GHC - the Haskell compiler - and one of the things that has come up a number of times, while [she has] been working on this, is that people don't have a super great idea about how it is that [she] actually optimize[s] a Haskell program and how [she]'d recommend that other people optimize a Haskell program."
    She acknowledges that is a broad subject and that it is easy to get the wrong idea that there is one, singular answer. In this video, she presents "one example of optimizing a Haskell program in some particular way that really focuses on a particular approach - which, in this particular example, is going to involve looking at GHC core."
    --
    Contact:
    Tweag Website: www.tweag.io/
    Tweag Twitter: / tweagio
    Alexis King's Twitter: / lexi_lambda

КОМЕНТАРІ • 49

  • @pedrovasconcelos7674
    @pedrovasconcelos7674 2 роки тому +23

    Great video and congratulations on not getting lost doing all those re-writings by hand! Anyway I think the video title undersells what you're actually achieving here: this is not just making a particular Haskell program faster, this is potentially making any program that uses this DSL faster by ensuring that the optimizer can eliminate layers of abstraction.

  • @foobar3202
    @foobar3202 2 роки тому +33

    Sorry to see Richard go, but delighted to see a video from Alexis! I've been a big fan of yours, so to speak, for some years now. "Parse, don't validate" has stuck with me for clearly articulating something quite fundamental and important.
    Re: ideas, you briefly mentioned arrows in the video, and I recall you were at one point working on a GHC proposal adjacent to them - perhaps a short introduction to/tutorial on arrows would make for a good topic? I'm sure I'm not alone in thinking that they look interesting, but I've never been able to really get my head around them.

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

      I've watched Haskell Deconstructed series, and there was part about Yampa, which utilize arrows. I think, that good point to start getting familiar with arrows. But be warned, im not an expert, and didn't used arrows by myself. But still, you might be intrested in this material.
      link:
      ua-cam.com/video/-IpE0CyHK7Q/v-deo.html

  • @AlanMalloy
    @AlanMalloy 2 роки тому +10

    The simplicity in the end of using the rewrite rules was very nice. I felt a bit lost for the majority of the video, though, because I didn't know why we were manually inlining all this stuff. Maybe you explained it early and I missed it, but only near the end did I realize, "Okay, we're simulating the inlining steps that GHC takes, so that we can diagnose where it gets stuck, and hopefully then we can give it some more hints to get it over the hurdle(s)." I guess it wasn't obvious to me that "Inline everything we see" is a good approximation of GHC's process. So I would have appreciated more early emphasis on the goals or rationale of the steps we were taking.

  • @soldierbirb
    @soldierbirb Рік тому +1

    You made me like haskell even more.+1 subscriber

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

    Very cool. Perhaps talking about your native delimited continuations patch, runtime details, garbage collection?

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

    will get it. Just don't get burnt out. Whenever you need a break, take one.

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

    that was awesome..and please please do more ..learned a lot ..thank you..

  • @yogeshsajanikar
    @yogeshsajanikar 2 роки тому +1

    Thanks @lexi_lambda for this video. It was an amazing watch. Of course, I need to watch again, and may be start with some simple examples myself.

  • @jackkensik7002
    @jackkensik7002 2 роки тому +3

    nice video, maybe go into coercions and the wanted's constraints system

  • @binaryblade2
    @binaryblade2 2 роки тому +2

    It's almost like it would be nice to have ghc to have a debug feature to perform a full inline operation that can be used for tasks like this. Seems like quite a bit of work for something mechanical.

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

    Explained in great detail! Thank you so much!!

  • @eignnx_1738
    @eignnx_1738 2 роки тому +2

    What a great walkthrough, I learned a lot! Thank you!
    One of the parts I didn't get: how did you know to stop inlining when you saw nested cut/paste calls? How could you tell ghc wouldn't be able to simplify those?

  • @sandymaguire8236
    @sandymaguire8236 2 роки тому +11

    Excellent video, thanks! Have you tried using HLS to automate inlining the definitions?

    •  2 роки тому

      Using the retrie plug-in you could get quite close, but It operates at module level. We would want it to work at the expression level

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

      do you mean Tactic programming via HLS.. or just maybe Typed or regular Template Haskell can be used..
      but then question will be do we analyze every module like this to optimize.

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

    Great video! I learned a lot from this.
    Would love to see a video on coercions :).

  • @yonko.blidxz
    @yonko.blidxz Рік тому

    Thank you SO much for this video :) it really helped me out!

  • @asdfghyter
    @asdfghyter 2 роки тому +2

    Would using the ghc plugin nat-normalize help to get the rules firing here?

  • @tricky778
    @tricky778 2 роки тому +1

    If we need to read and cause changes to "core" code, why do we bother with the Haskell front end language in the first place?

    • @garethrowlands
      @garethrowlands 2 роки тому +1

      Well, most of the time we do not need to read or optimise the core. And in this case, the optimisations apply to the library and any program using it.

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

      @@garethrowlands can we predict when, how often, how difficult it will be to optimise via core?

    • @garethrowlands
      @garethrowlands 2 роки тому +3

      @@tricky778 well those are good questions. Most of the time, programs go fast enough without reading down into core. Your mileage may vary!

  • @Dregntael
    @Dregntael 2 роки тому +1

    Thanks for the very nice video! One thing I am wondering: do these rewrite rules also deal with the case where the length is something like `(0 + 0) + (0 + 0)`? It seems none of the rules would apply immediately, which is kind of a shame.

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

      You could probably add a rule that simplifies toward right associativity: rewrite (x + y) + z to x + (y + z). Applying that to your example, you’d get 0 + (0 + (0 + 0)) and then the other rules would apply.

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

    Alexis, thank you for very instructive hands-on video.
    In the first part of the video, before re-write rules, you substituted expressions with their evaluated values.
    Would it be helpful to have re-write rules on values level to facilitate such substitutions in addition to the re-write rules on types level you used in the second part of the video?
    Or have an optimizer that would decide that an expression can be evaluated at compile time?

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

    that differential equation arrow library is amazing, where can I get it!!!!

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

    I'm learning tNice tutorials, guitar, and 3d animation at the sa ti what am i doing to myself?

  • @ArtemijSmyslovskij
    @ArtemijSmyslovskij 2 роки тому +1

    What's the name of the colour scheme?

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

    so difficult, i dont understanding

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

    A better video title: @lexi_lambda: How to make a Haskell program 5x faster with 16 lines of comments
    Great work Alexis, I'd love to see you do more of these videos - if you could do some on the work you're doing to improve GHC's performance, I think a lot of people would find that really interesting too.

    • @0LoneTech
      @0LoneTech Місяць тому

      Those are not comments, it's a compiler pragma.

  • @hellwolf4liberty
    @hellwolf4liberty 2 роки тому +1

    can bugs happen in rewriting rules, or it is statically checked against correctness somehow?

    • @foobar3202
      @foobar3202 2 роки тому +2

      Bugs can indeed happen. Quoting from the GHC users guide (which is a great resource by the way): "GHC makes absolutely no attempt to verify that the LHS and RHS of a rule have the same meaning. That is undecidable in general, and infeasible in most interesting cases. The responsibility is entirely the programmer’s!"

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

      ouch, wow, quite a risky move from software engineering perspective...

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

      @@hellwolf4liberty well, you could always write tests for it, like any code. There's lots of things the compiler can't check, in general, so you have to test. If lack of compiler proofs was really *that* bad, no Ruby program would ever work. You should see the tests in writing for a small typescript app - it would be great if the compiler could prove everything but I'm having to write tests.

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

    Nice video. Which IDE is this?

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

    good tutorial, one question about soft recording. How do you do it? lol

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

    how does one download or use the script from your description

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

    All this inlining and simplification by hand is really tedious. We definitely should have haskell-language-server plugin for this. There actually was something called HaRe (Haskell Refactoring) a while ago...
    Another thing is that she is second-guessing the compiler. We don't actually know if all these inlinings and simplifications actually fire...

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

    yup

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

    43:20 Wouldn't that transformation be forbidden for the optimizer to do, since it turns something explicitly marked as strict into lazy (and even completely eliminated)?

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

      I was thinking that too. Since the rewrite rules do fire, that seems to imply that somehow it does still reduce in a similar manner. I wonder what's going on here.

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

    Guide how to write 16 strings within 1 hour. It's pretty tought when it dives into compiler.
    But nevermind. Not sure that video was helpful on my level of understanding, but such peeks into optimization machinery certanly demestificates some of misconceptions.
    Thanks for video!

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

    norman is that you

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

    equalize it

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

    TeacNice tutorialng is your talent!

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

    Be consistent, make mistakes, experint