leddoo
leddoo
  • 7
  • 420 538
but what is 'a lifetime?
how i think about lifetimes.
hope it helps!
the article: smallcultfollowing.com/babysteps/blog/2018/04/27/an-alias-based-formulation-of-the-borrow-checker/
discord: discord.gg/X4znAuxJ
zhlédnutí: 58 953

Video

going fast is about doing less
zhlédnutí 170KPřed rokem
optimization isn't always about multi-threading and optimizing hardware utilization. in fact, most performance work is about simply doing less. tantan's video: czcams.com/video/jkHqrkcEHRc/video.html philosophies of optimization (highly recommend): czcams.com/video/pgoetgxecw8/video.html simple code high performance: czcams.com/video/Ge3aKEmZcqY/video.html slides & code: github.com/leddoo/vids/...
it took me 1 month to fix this compiler bug
zhlédnutí 46KPřed rokem
one pesky little bug. one month of development. more about SSA form: introductory stuff: - en.wikipedia.org/wiki/Static_single-assignment_form - blog.yossarian.net/2020/10/23/Understanding-static-single-assignment-forms converting to ssa form: - ssa form: www.cs.cornell.edu/courses/cs6120/2022sp/lesson/6/ - dominators: www.cs.cornell.edu/courses/cs6120/2022sp/lesson/5/ - and: www.cs.rice.edu/~k...
how i got rid of semicolons in my scripting language
zhlédnutí 30KPřed rokem
i used go's technique :^)
are stack based vms really slower?
zhlédnutí 18KPřed rokem
exploring stack & register vm performance in more technical depth: how dependencies between instructions affect performance. previous video: czcams.com/video/14CPI1qBd7o/video.html lecture series: czcams.com/play/PL5Q2soXY2Zi8J58xLKBNFQFHRO3GrXxA9.html (you can probably start with episode "11: Microarchitecture") music: Rush Hour Shift - Speedy The Spider more stuff & links: i did promise that ...
why my scripting language is already faster than python
zhlédnutí 89KPřed rokem
python uses a stack based virtual machine. my language is register based. that's why it is faster. this video explains what that means. chapters: 0:00 - intro 0:10 - demo 0:26 - performance 1:23 - how python works 2:35 - register machines 3:55 - conclusion
Introduction to Vector Graphics Rendering
zhlédnutí 9KPřed 2 lety
This video covers the basics of vector graphics: - How vector images are defined. - Filling vector shapes. Source code: github.com/leddoo/edu-vector-graphics Some next steps: - Write a faster rasterizer by reusing previous pixel winding calculations. - Fill pixels in an image instead of printing to the console. - Anti-aliasing & more robust maths. - Bezier curves & flattening them to line segme...

Komentáře

  • @comcxyang7395
    @comcxyang7395 Před 4 dny

    Best lifetime video ever!

  • @akshay-kumar-007
    @akshay-kumar-007 Před 5 dny

    Thanks for the video. New to Rust as I'm trying to go through a codebase written in Rust. The shear amount of syntax in Rust is overwhelming tbh. This cleared some bits

  • @xmorse
    @xmorse Před 14 dny

    Is this how wasm works too?

  • @rogergalindo7318
    @rogergalindo7318 Před 16 dny

    still waiting for the struct lifetimes vid!

  • @adamurban6904
    @adamurban6904 Před 16 dny

    Brilliant!

  • @small6732
    @small6732 Před 22 dny

    Do you know what is 醍醐灌顶 in Chinese? Your video is😀😀.

  • @Leonhart_93
    @Leonhart_93 Před 27 dny

    Re-inventing the wheel trying to fix a problem by making the implementation overly obscure.

  • @dagoberttrump9290
    @dagoberttrump9290 Před 28 dny

    shouldn't the input parameter outlive the output parameters since the output references the inputs?

    • @akshay-kumar-007
      @akshay-kumar-007 Před 5 dny

      output is returned to caller function and the input params only live till function's execution context is in call stack.

  • @telotawa
    @telotawa Před 28 dny

    8:28, hold on, ch10 of the book says it's the *shorter* of the lifetimes of x and y the example that makes me think this model is wrong goes like this: say you replaced x and y with Strings so that they aren't `static lifetime and if you tried to use l1 after making x go out of scope (and its memory was cleared), it'd still give you an error, even though it points to data owned by y, which would still be valid modeling 'a as a set of memory that l1 can point at, which contains both 'x and 'y, seems to contradict this: that would imply 'a is valid when 'x OR 'y is still valid, but the book says it's while 'x AND 'y are still valid which one is actually correct? I trust the book more than this

  • @DB-go6rv
    @DB-go6rv Před měsícem

    As a pretty senior developer coming to Rust, this explanation in terms of memory was really helpful to grok the concept. Nice examples, clearly annotated too!

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

    The moment I knew for sure that I now understand lifetimes was when I was contributing a PR to the bat project on Github. I had to modify a function so that it takes an iterator of a tuple of two references, one of which is a struct with a distinct lifetime parameter, extract a &str from this struct, then collect and return them in a HashMap (it's confusing, I know). Rust analyzer yelled at me the first time I saved, but didn't provide a fix. I thought briefly about what the two lifetimes actually meant, typed out `'t: 'r` along with a comment that explained why, hit save and it worked. It's just one simple line but to me it was a very significant milestone. I've been writing Rust for 4 years and counting (3½ at the time of this PR), and writing that line (and more importantly, fully understanding what it's doing and why it is so) was the singular moment when I was able to say to myself, "huh I'm actually reasonably competent in Rust now".

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

      For anyone interested in the actual code, it was a function named `get_syntax_mapping_to_paths` in sharkdp/bat#2755.

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

      For anyone interested in looking at the actual code, it was a function named `get_syntax_mapping_to_paths` in sharkdp/bat, issue 2755. Stupid CZcams hates links so you'd have to find it yourself.

  • @JH-pe3ro
    @JH-pe3ro Před měsícem

    There's a strong path-dependency to how we've ended up in "registers are faster", I think(and I was aware of that before the video, though it's a great explanation of why); register architectures are intuitive when computers are viewed in terms of arithmetic processing, and they map well to local variables. Therefore we have hardware that engages with that, provides a lot of enumerated registers, and asks for languages to utilize all of them, and that has a consequence on VM design, since the VM's goal is to remap program description to efficient hardware utilization: if it looks stack-y, then the JIT rewrites it to register-y code. On the other hand, the CPU architecture can avoid this and do something like Minimal 64x4, a non-pipelined hobby computer using discrete logic: it achieves very good performance at a relatively low clock rate by reducing the register set and optimizing the instruction set around zero page memory(a construct which exists on 6502 as well, but is used supplemental to registers), thus algorithm descriptions are smaller and the total sequential work is smaller than on other 8-bits, despite having a lower "MIPS" rating. I believe the distinction between VMs would be relatively less important on Min 64x4 because the stack VM's instruction set would also benefit from the ability to code random access efficiently. I've started to think that local variables are worth questioning, though. They serve a certain "black-boxing" purpose of presenting short routines as a matter of loading up the registers in an initial state, doing the computation, and then writing that back using the stack as a protocol between that routine and the rest of the program. But the usual alternative to a stack protocol is a buffer, and buffers have certain benefits in terms of coordination of resource use. If the buffer were implemented like a ring buffer and the computer optimized around that, it presents ideas like the Mill computer's "belt", an interesting concept, albeit one that sadly still hasn't shipped anything.

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

    This is awesome, you have a way of breaking down complex things and using comparison that resonates with me. Looking forward to the borrow checker video.

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

    This video explaining Rust's lifetimes is the best I've seen! Looking forward to more from you! Keep it up!

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

    Thank you, this video is a life-saver.

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

    man, what a great video. subscribed! 100k subs with this level of quality content is inevitable.

  • @voncth5791
    @voncth5791 Před 2 měsíci

    Still dont understand completely but the regions of memory example is far easier to understand

  • @user-rk9rp2ni9l
    @user-rk9rp2ni9l Před 2 měsíci

    Great video! Keep it up

  • @awfultrash888
    @awfultrash888 Před 2 měsíci

    Pretty good video man!

  • @stercorarius
    @stercorarius Před 2 měsíci

    you did a good job on this one! what do you use to create / edit your videos?

  • @DiogoBaeder
    @DiogoBaeder Před 2 měsíci

    Really nice video, man, it helped improving my understanding of lifetimes. Thinking of memory regions made more sense to me.

  • @sefumies
    @sefumies Před 2 měsíci

    Excellent, clear and concise! Thank you!

  • @Cmax15
    @Cmax15 Před 2 měsíci

    Duddeeeeee! You are awesomeee!

  • @bobhardcore6707
    @bobhardcore6707 Před 3 měsíci

    ...no, with bigamism...

  • @mikemardis
    @mikemardis Před 3 měsíci

    Newbie here, struggling (of course) with Rust concepts. I really like your alternate approach to understanding lifetimes. It helped me a lot.

  • @LeviNotik
    @LeviNotik Před 3 měsíci

    Amazing explanation and presentation. Keep 'em comin!

  • @luigidabro
    @luigidabro Před 3 měsíci

    But wouldn't a lifetime be atleast the same size as the largest sub-lifetime, instead of larger than the largest?

  • @lucvaroqui2754
    @lucvaroqui2754 Před 4 měsíci

    Very nice alternative view on lifetime understanding, I'll try to apply it in my day to day Rust thinking and see how it helps! Bravo 👏

  • @shiva.sharan
    @shiva.sharan Před 4 měsíci

    Great video 🤘🏽🤘🏽

  • @lukdb
    @lukdb Před 4 měsíci

    You really helped me out with this one. Thanks.

  • @meka4996
    @meka4996 Před 4 měsíci

    Very clear! Thank you

  • @cos2518
    @cos2518 Před 5 měsíci

    wonderful lecture! thanks

  • @kleinmarb4362
    @kleinmarb4362 Před 5 měsíci

    Very nice!

  • @ahm_d3762
    @ahm_d3762 Před 5 měsíci

    here how the 'r can point to &x or &foo while x out of scope? 5:40

  • @arisweedler4703
    @arisweedler4703 Před 5 měsíci

    Great video. Love the comparisons of various stages of IR at the end. Since this video has come out, godbolt has added the ability to do this!

  • @olsuhvlad
    @olsuhvlad Před 5 měsíci

    13 And no man hath ascended up to heaven, but he that came down from heaven, even the Son of man which is in heaven. 14 And as Moses lifted up the serpent in the wilderness, even so must the Son of man be lifted up: 15 That whosoever believeth in him should not perish, but have eternal life. 16 For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life. 17 For God sent not his Son into the world to condemn the world; but that the world through him might be saved. 18 He that believeth on him is not condemned: but he that believeth not is condemned already, because he hath not believed in the name of the only begotten Son of God. 19 And this is the condemnation, that light is come into the world, and men loved darkness rather than light, because their deeds were evil. 20 For every one that doeth evil hateth the light, neither cometh to the light, lest his deeds should be reproved. 21 But he that doeth truth cometh to the light, that his deeds may be made manifest, that they are wrought in God. (Jn.3:13-21)

  • @jhager03
    @jhager03 Před 5 měsíci

    Very useful, thank you.

  • @NDValle
    @NDValle Před 5 měsíci

    Great video! Thanks!

  • @okuno54
    @okuno54 Před 6 měsíci

    I'm suddenly very thankful for monads, which would explicitly require the programmer to say which result they really mean, but you get the option of either. In Haskell, we have `read a <&> (+) <*> do { modify (+1) a; read a }` giving 3, and `read a <**> (+) <$> do { modify (+1) a; read a }` giving 4. What perhaps is not apparent is that the "correct" semantics for both just falls out of the type system. I can directly translate the first into a more familiar syntax `*a + { a += 1; *a}`, but the second would require me to take advantage of the commutativity of addition `{ a += 1; *a } + *a`. The reason why the two sides flip around is because `(<**>) === flip (<*>)` and `(<&>) === flip (<$>)`, where `flip` exchanges the order of the first two arguments. The types of these operators are not symmetric in their arguments, so you can know which one has to be which.

  • @knight_kazul
    @knight_kazul Před 6 měsíci

    You have pretty eyes.

  • @hansdampf2284
    @hansdampf2284 Před 6 měsíci

    I will try to use that model in the future let’s see how it goes. Having some more examples would be helpful in those videos I think

  • @adante270
    @adante270 Před 6 měsíci

    great little video, thanks!

  • @CrystalLily1302
    @CrystalLily1302 Před 6 měsíci

    Just getting into rust and one thing I wish was clearer was a way to cleanly tell the compiler "this reference will be valid during this scope" i.e. fn foo(bar: impl Iterator<Item = &my_struct>) does not compile but for some reason fn foo<'a>(bar: impl Iterator<Item = &'a my_struct>) does compile and I don't really understand why that lets the compiler accept it I appreciate that this lets it compile but I haven't guaranteed any information about that reference, only named it, but maybe this will enforce that the references in the iterator cannot go out of scope during this function call, if that is the case then I wish that was more obviously written in the lifetimes documentation.

  • @andr6192
    @andr6192 Před 6 měsíci

    Great video! I think a very important note about ‘static is that it also refers to owned values when used as a trait bound. That tripped me up when first learning, thinking I effectively required leaked resources if adding that bound

  • @yingliu4203
    @yingliu4203 Před 6 měsíci

    The region concept is confusing (an error?) at 8:40 and 10:23, The outer region means the shortest lifetime of a set of inner regions - calling this relationship using set and subset is the problem: the outer lifetime should be a subset of the inner lifetime. Both the box drawing and subset mean exactly the opposite: outer is a subset of any inner.