Hello!

I'm @captainsafia!

safia.rocks

content warning

this is a technical talk with no code.

@captainsafia

difficulty warning

this is a beginner-friendly talk!

@captainsafia

bit.ly/jmp-memlng-live

Follow along!  🎉

@captainsafia

turing machine

Von Neumann architecture

A machine that thinks is remarkable.

A MACHINE THAT REMEMBERS WHAT IT THINKS IS REVOLUTIONARY.

@captainsafia

""But my laptop has 16 gbs of memory.

Why should i care about memory performance?""

@captainsafia

truly timeless.

@captainsafia

Language agnostic.

@captainsafia

User expectations and demands grow faster than memory availability.

@captainsafia

@captainsafia

Not all your users are using the latest tech.

@captainsafia

You don't want to be that app.

YOU KNOW THAT APP.

Let's go to class.

Premature freeing

@captainsafia

memory leak

@captainsafia

But we (kind of) don't have to worry about that.

@captainsafia

garbage collection

Sounds Great?

kind of.

@captainsafia

CPU Overhead

PAUSE TIMES

memory overhead

V8

@captainsafia

The Memory Heap

@captainsafia

@captainsafia

Locality and fragmentation

how do you allocate memory?

@captainsafia

FIRST FIT

@captainsafia

BEST FIT

@captainsafia

WORST FIT

@captainsafia

That's the language agnostic stuff.

@captainsafia

V8 allocates objects in memory into contiguous chunks, or spaces.

  • New space

  • Old pointer space

  • Old data space

  • Large object space

  • Code space

@captainsafia

So, we've allocated objects in memory.

@captainsafia

The Memory Heap

@captainsafia

But, how does V8 collect garbage memory?

@captainsafia

Run a short garbage collection cycle.

Halt the program.

@captainsafia

Scavenging

@captainsafia

from space

TO Space

@captainsafia

@captainsafia

from space

TO Space

@captainsafia

from space

TO Space

@captainsafia

from space

TO Space

@captainsafia

from space

TO Space

@captainsafia

from space

TO Space

Mark and Sweep

@captainsafia

@captainsafia

Marked as 0

Marked as 1

@captainsafia

Marked as 0

Marked as 1

@captainsafia

Marked as 0

Marked as 1

@captainsafia

Marked as 0

Marked as 1

@captainsafia

Marked as 0

Marked as 1

@captainsafia

Marked as 0

Marked as 1

@captainsafia

Marked as 0

Marked as 1

@captainsafia

intelligent Memory Allocation

nicely designed garbage collectors

=

less painful programming

How much memory is my application using?

 

How often do GC cycles occur in my application?

@captainsafia

The right tools for a messy job.

@captainsafia

@captainsafia

Let's try it.

@captainsafia

  • memwatch

  • heapdump

  • v8-profiler

  • performance monitoring tools

@captainsafia

Enough with the v8, Already!

@captainsafia

chakra

uses mark and sweep

@captainsafia

chakra

runs the gc on a concurrent thread

@captainsafia

chakra

allocates scalars into a separate space

@captainsafia

chakra

(sometimes) runs the garbage collector on tab switch

@captainsafia

Spidermonkey

uses mark and sweep

@captainsafia

Spidermonkey

utilizes incremental marking

@captainsafia

Spidermonkey

has a compacting gc

@captainsafia

so we've got this knowledge.

@captainsafia

WHen should WE USE IT?

@captainsafia

""I had your To-do list app open in my browser and it makes it crash after a while!""

@captainsafia

""your app has jank and jitters""

@captainsafia

""your app just sucks""

@captainsafia

you can do it.

@captainsafia

memory management is hard.

@captainsafia

garbage collectors get better every day.

@captainsafia

v8 makes it easy and obfuscates the details from us.

@captainsafia

But eat your vegatables and appreciate your garbage collector. ❤️

@captainsafia

live long and prosper! 🖖🏾

safia@safia.rocks — SAFIA.ROCKS — @captainsafia

memory-in-javascript-long

By Safia Abdalla

memory-in-javascript-long

The deck for my talk on memory management in JavaScript.

  • 583

More from Safia Abdalla