Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Server Memory - Chernivtsi JS 2019
Search
Андрей Листочкин (Andrey Listochkin)
June 22, 2019
Programming
170
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Server Memory - Chernivtsi JS 2019
Андрей Листочкин (Andrey Listochkin)
June 22, 2019
More Decks by Андрей Листочкин (Andrey Listochkin)
See All by Андрей Листочкин (Andrey Listochkin)
Everybody Stand Back! I Know Regular Expressions
listochkin
0
240
Command-line scripting with Rust. Wait, what?!
listochkin
0
420
Server Memory - BuildStuff Ukraine 2019
listochkin
0
76
10 Years Later
listochkin
0
400
Managing Managers - DevTalks iHUB
listochkin
0
88
Time, Numbers, Text
listochkin
1
680
Software Licensing: A Minefield Guide
listochkin
0
190
We Make Bots. For Real
listochkin
0
480
Devops for A Busy Developer - XP Days 2016
listochkin
0
200
Other Decks in Programming
See All in Programming
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
520
クラウドゲーミングのパフォーマンス最適化に挑む / Cloud Gaming Performance Tuning
vivion
0
310
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
240
Next.js: The final boss of Web Performance
guaca
0
370
當我們開始不讀 Code - AI Agent 時代,Code Review 與 Clean Code 還剩下什麼?
jame2408
1
350
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
240
AIがコードを書いてくれる時代、我々は何を確かめるのか
yosuke_furukawa
PRO
13
5.3k
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
200
AIが生成したコードは読むべきか?抽象化設計とコードの品質保証 / abstraction-design-and-quality
minodriven
12
7.8k
Inertia Rails: The One-Person Framework with React & Friends
skryukov
0
200
[2026-10-09]一枚の布で作らなくてもいい。 信頼性は「パッチワーク」で紡がれる~既存の運用と新しい可能性をつなぎ合わせてきたCREの話~
tosite
0
120
AI時代のFlutter品質設計 — アプリ品質を守るQuality Layers
omatty198
0
330
Featured
See All Featured
How to make the Groovebox
asonas
2
2.5k
Paper Plane (Part 1)
katiecoart
PRO
2
12k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Raft: Consensus for Rubyists
vanstee
143
7.8k
Tell your own story through comics
letsgokoyo
1
1.1k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
520
Transcript
None
@listochkin fb.com/tektonna
Not a JavaScript talk
No CSS No frameworks No Node
A bit deeper than most talks on similar subject
None
How programming languages work
Just-in-time compilers Garbage Collection
Memory Management
Server runs our programs
CPU Caches RAM Swap Disk Network
Operating System
None
Pages
4k
Virtual
2 processes [0 … ∞]
Oh, I got a pointer at 4096 What’s at 4095?
Page fault
Allocate page But not really
Once you start writing to it
not 4k?
None
None
malloc
None
malloc me some memory
a pointer
free(pointer)
malloc malloc malloc free malloc free free
Forget to free Free the wrong pointer Read from unallocated
memory
Can we do better?
Reference Counting
None
const players = [ … ] players.forEach(p => makeMove(p))
a = … doX(a) yield a
scope
if ( … ) { let a = … …
}
None
C++: std::shared_ptr
None
Optimizations
Delayed Counting
Don’t count local references
function (user) { let email = user.email; … … }
Delayed deallocation
Cycle Collector
None
None
Compile time ref-counting
Several types of pointers
Ownership
Forbids cycles by forbidding several owning references at the same
time
None
None
None
Perl 1987 - today Python 1991 - 2001 PHP 1994
- 2009
Multiprocess deploys
fork
Copy on Write
Worker Accepts requests As memory use raises: Stop accepting requests
Complete in-flight requests Terminate
Master Keep track on workers Start new workers Signal them
to terminate when memory pressure is high
“Pre-fork”
Load the framework Load app code Run full GC Start
forking process to accept requests
None
None
“Processes”
Tracing GC
1959 60 years ago
Start at Root references Follow all references Build a live
objects tree Delete all objects not part of the tree
Ruby Java JavaScript Lua Go
Roots?
Constants Global variables Local variables Closures Thread-locals ...
Mark & Sweep vs Mark-Compact
None
Can you move objects after mark?
Team Sweep: Go Ruby* Lua Embedded JS engines Erlang
Pros: Pointers don’t change Native extensions Easier to implement
Team Compact: Java JavaScript Ruby* Haskell
Pros: Less memory fragmentation over time Cons: Harder Takes longer
to do a GC
Mark all memory
None
Incremental Marking
3-colored algorithm by Dijkstra™
None
None
None
None
None
What is a barrier? if statement
else branch is very rare CPU branch predictor
Parallel marking
None
None
Lazy Sweep
Generational
Temporary data
Major vs Minor GC
Pointers from Old objects to new objects
Remembered Set
Major GC Scan roots only Bigger object graph
Minor GC Scan roots + RS Small object graph
None
Modern GCs are hybrid
None
None
C-extensions
Can’t move objects if their references are passed to an
extension
Can’t add WB
RGen GC
2 types of objects WB-protected WB-unprotected
WBu are never OldGen
OldGen -> WBu WBu to Remembered Set
Mark WBus on every minor GC
1 stw to mark all WBu in RS
None
None
Adding compaction for WBp
None
V8
Minor GC Parallel
Major Parallel marking Parallel / Concurrent Compact || Sweep
None
When to trigger GC?
Out-of-Bounds GC
request? Minor GCs response is sent? Major GC
Firefox Run GC in background tabs first instead of current
tab
Chrome Animation frame
Walking the memory
Cache locality
GPU
OS Pages pre-forked processes malloc zones GC Pages Remembered Sets
Barriers
None
None