Weak JavaScript - HTTP 203

Поділитися
Вставка
  • Опубліковано 24 сер 2024

КОМЕНТАРІ • 49

  • @me99771
    @me99771 4 роки тому +38

    "garbage collection only happens when the browser thinks it has downtime and only when it's under memory stress"
    We solved it. That's why chrome uses so much ram.

  • @lotsofloops
    @lotsofloops 4 роки тому +25

    14:55: You can use primitive wrapper objects. new WeakRef(new String("hi")) works, since the String constructor returns a String wrapper object. In fact, primitives are automatically upgraded to a wrapper object whenever methods are called on them, since primitives don't have prototypes. Primitive wrappers also get downgraded to primitives automatically in some cases.
    As for equality, note that (new String("hi")) !== (new String("hi")), but "hi" === "hi". Primitive strings aren't equal because they are "identical", but because the ECMAScript spec says they are equal. Section 7.2.13 says strings are equal if "x and y are exactly the same sequence of code units (same length and same code units at corresponding indices)". (although idk how they are actually implement any of this)
    Primitive wrapper objects are somewhat interesting but not very useful, except for niche use cases like this.

  • @JimishFotariya97
    @JimishFotariya97 4 роки тому +13

    "Gone But not Forgotten" 💫

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

      Who's gone?

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

      What happened to Paul Lewis?

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

      @@seanpheneger6632 I don't know 😂

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

      @@seanpheneger6632 Nothing. He used to be in HTTP 203 few years ago. ATM he's part of the DevTools team.

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

    Tbh, I love these videos.
    Coz half the time I have no idea what they are talking about
    and most the time I am like - uh? What? Come again?

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

    Main takeaway from the video: you can optionally chain function invocations with `?.()`. But seriously, the video was super interesting. I wonder what happens if a FinalizationRegistry holds a reference to itself and gets garbage collected... this breaks my brain. Missing the update on the string pool though ;)

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

      Yeah string pool thing update is I am curious about. Cause that is the most confusing part in this video. Premitive types also should get garbage collected don't they??

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

      technikhil Primitive values as I understand are stored in the stack and not the heap. So if you declared a Boolean inside a function call, that Boolean would be popped off the stack and would no longer exist once the function call had ended.
      This doesn’t address what happens with strings or closures and I don’t know enough about that yet to offer any explanation.

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

      @@mysterbirdtrooper6516 yeah sorry I meant by primitives in closure scope only. I guess new let and const might be making some change in how they are handled.

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

      Here is another use case ua-cam.com/video/TPm-UhWkiq8/v-deo.html

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

      wooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooow

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

    Love these ... being stuck home at COVID ... I don't get the chance to have these discussions and it's great having Surma and Jake go back and forth on this advanced topic is great!

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

    00:50 Exactly you are right this is the best part 😂😂😂😂

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

    I had no idea that a weak reference was even a term. It sounds like what happens when you create an array in a C++ function and then return it from that function, but you get a compiler warning that the array is not guaranteed to exist later on when you need it

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

      Java has it explicitly as well for example. The idea is just that you can hold a reference to something, but that reference doesn't prevent GC from removing the object. For cases where you want to work with objects as long as they're available and thereby need a reference, but don't want that reference to prolong the object lifespan.

  • @ihavegotnoidea
    @ihavegotnoidea 4 роки тому +7

    Okay so quantum references.

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

      for a comment made by "ihavegotnoidea" this seems fairly accurate

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

    I definitely can appreciate the correction about why they're not iterable _before_ you explained your current understanding! Lots of people correct things like that after you've internalized the information, and it can be really difficult to undo it in your mind.

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

    Can we take this information authoritatively?

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

    21:49 Shouldn’t he token be returned by `registry.register()`? It seems a bit extra to have to care about the actual implementation of the token; looks like it really can be any unique value (ideally, a symbol, but that’s not required).

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

      I asked one of the proposal champions what the reasoning is: “design-wise, the ability to pass in a key lets you group multiple registrations with a single key, which is more powerful.
      performance-wise, having a key makes things slower since we need to track it in a map, so being optional is nice.”

  • @Manivelarino
    @Manivelarino 4 роки тому +9

    I'm having trouble keeping up with these topics lately 😅

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

    If one of the motivations for WeakRefs/FinalizationRegistry is to allow garbage collection in one context to trigger reclamation of memory in another context, e.g. in WebAssembly or a Worker (via Comlink, say), then are browsers likely to invoke garbage collection in one context when a related but distinct context is under memory pressure? If I have large WebAssembly objects associated with small Javascript objects that become unreferenced, I'm wondering how often this will actually help. I know this is likely implementation-specific, but what do current implementations do?

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

      I don't think “memory pressure” is determined per realm (or scope). The entire system is under memory pressure and that will trigger garbage collection. That will cause your small JS object to get GC’d and that in turn will trigger your code to free up Wasm memory. That being said, Wasm memory is special. It can only grow, not shrink, so if anything you are preventing _further_ allocations instead of reducing occupied memory.

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

    @Surma Why do I have to pass in the unregistertoken? Can it not be on lines of settimeout where settimeout returns me the token to in turn pass to clearTimeout? Am I missing something?

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

    Hey Surma, can we get a superCharged episode, where you build yourself a teleprompter for HTTP 203

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

    Live for this.

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

    This is AWSOME!!

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

    sUUper aDVanCE stAFf

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

    6:27
    In the second block, is an assignment to a key with the value of profile `profile` with `auxiliaryData.set` implied/missing before use of `auxiliaryData.get` on the last line?

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

      Yeah maybe, but I'm using optional chaining so the code doesn't break either way :9

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

      @@Chill157 yes

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

      but can we get it free noooooooooooooooo

  • @dz4k.com.
    @dz4k.com. 4 роки тому +5

    I think it's "non-compliant"

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

    some weird audio cuts at 17:58

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

    ok im proper confused now

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

    Not convinced as to why this is useful - maybe I should read up on the use case for comlink

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

      I guess surma mentioned that there are strong usecases in webassembly and javascript interoperability. If I am not mistaken.

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

      technikhil yeah, but I think I need to see a concrete app to that uses it to see the point - and also it doesn’t answer why such a generic API was developed for such a specific problem

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

      @@rlamacraft yeah I am thinking of it too. Let me know if you come up with something and I'll let know if I come with something too. Thanks

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

      That basically allow an arbitrary class(or object) have deconstructor without any code that call deinit function.
      You can do that manually, but when is an object not needed(will be GC) is not easy to tell, since things passes around and it can be circular.
      That's an excellent feature, that won't be adopted unless everyone say yes.

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

    Bizarro 302. Garbage collection, weak refs, dbl-rAF, isInputPending, rIC, workers...Javascript timing has become the NYC subway system.

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

    hahahahahahaha 🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣