On "simple" Optimizations - Chandler Carruth - Secret Lightning Talks - Meeting C++ 2016

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ธ.ค. 2024

ความคิดเห็น • 24

  • @MattGodbolt
    @MattGodbolt 7 ปีที่แล้ว +73

    Wow: thanks for the amazing shout out for Compiler Explorer :)

  • @SolomonUcko
    @SolomonUcko 4 ปีที่แล้ว +7

    Moral: run your optimizer repeatedly until the code is optimized enough ;)

  • @TheArtikae
    @TheArtikae 4 หลายเดือนก่อน +1

    Update: Clang now identifies that the return value is 10!
    Funnily enough, if you don’t specify v.reserve(4), you still get an allocation, but the allocation is totally unused. It calls operator new, then operator delete, then returns 10.

  • @pfeilspitze
    @pfeilspitze 5 ปีที่แล้ว +10

    Did you know that searching for "the number of inlining shall be three" finds Monty Python videos, not this one?

  • @MrAbrazildo
    @MrAbrazildo 8 ปีที่แล้ว +9

    Maybe you should create even more flags for the compiler. Not to throw all of them at the user's face, but to have flags that can "unlock" new options/flags, if the user is trying to go deeply in optimization.
    Just an idea.

  • @kamilziemian995
    @kamilziemian995 2 ปีที่แล้ว

    I really like Chandler Carruth's talks.

  • @johnbaxter7582
    @johnbaxter7582 ปีที่แล้ว

    I like the idea of the optimiser going out to launch 😆

  • @rubberduck2078
    @rubberduck2078 2 ปีที่แล้ว +5

    here's how you optimize for less alllocations: don't write code that does many allocations

    • @tau9285
      @tau9285 2 ปีที่แล้ว +3

      Exactly! No one who actually cares about performance would expect the compiler to magically fix this kind of stuff. There is a finite time budget for optimizations, and it should not be spent on trying to mend such obivously-pessimized code.

  • @xealit
    @xealit ปีที่แล้ว

    Optimizer indeed should be able to optimize out such a trivial example with literal input in the program source etc. But what's the point? In reality, such examples probably show up only in some simple toy-benchmarks.

  • @iddn
    @iddn 8 ปีที่แล้ว +6

    I don't see why the compiler would be expected to optimize that out. Sure, the return value is one thing but someone may actually want the heap allocation side effects

    • @ihatenumberinemail
      @ihatenumberinemail 8 ปีที่แล้ว +31

      >want the heap allocation side effects
      That's horrible!

    • @totheknee
      @totheknee 7 ปีที่แล้ว +7

      Then pass in the vector, or use gcc. Better yet, become a hair stylist.

    • @skepticmoderate5790
      @skepticmoderate5790 4 ปีที่แล้ว +14

      "want the heap allocation side effects"
      You can turn off optimization. But regardless, I think you're doing programming wrong.

    • @abuyoyo31
      @abuyoyo31 2 ปีที่แล้ว

      The vector in this particular code snippet is destroyed upon function exit. There is no such side effect.

    • @jcramberry
      @jcramberry 2 ปีที่แล้ว +4

      @@abuyoyo31 Potentially there could be an sbrk or mmap call done by malloc which would be optimized out. But relying on that behavior here would be more than a little crackpot

  • @dengan699
    @dengan699 4 ปีที่แล้ว +2

    Soooo basically it is a rant because the compiler doesn't *acually* runs your code and hard-code into resulting executable? .. interesting

  • @rubberduck2078
    @rubberduck2078 2 ปีที่แล้ว +2

    Why should this be optimized? It shouldn't.