Weak JavaScript - HTTP 203

preview_player
Показать описание
Surma and Jake take a look at 'weak' JavaScript, specifically WeakMap, WeakSet, and the new and shiny WeakRefs.



Рекомендации по теме
Комментарии
Автор

"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.

me
Автор

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.

lotsofloops
Автор

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!

robertluong
Автор

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?

pramodjingade
Автор

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 ;)

mathisbullinger
Автор

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

workflop
Автор

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.

thisberandom
Автор

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

Daniel_WR_Hart
Автор

@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?

technikhil
Автор

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).

parzh
Автор

Can we take this information authoritatively?

cipherxen
Автор

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?

rhashimoto
Автор

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?

disk__
Автор

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

chaos_monster
Автор

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

Manivelarino
Автор

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

rlamacraft
Автор

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

Textras
visit shbcf.ru