SlideShare a Scribd company logo
1 of 60
Download to read offline
Go &
The garbage collection
“
Joris Bonnefoy
DevOps @ OVH
@devatoria
2
Introduction
Reminder of basic algorithmic structures
» Objects have a pointer to the next element of the
list
» The last element have a null pointer
Linked list 4
» Objects have pointers to the next and the previous
element of the list
» The first element have a null previous pointer
» The last element have a null next pointer
Doubly linked list 5
» Objects have pointers to the next and the previous element of the
list
» The first element have a previous pointer to the last element of the
list
» The last element have a next pointer to the first element of the list
Circular doubly linked list 6
A simple problem
How to free a dereferenced object?
How to free a dereferenced object? 8
How to free a dereferenced object? 9
How to free a dereferenced object? 10
A solution
The garbage collection
The garbage collection
» John McCarthy - 1959 - Lisp
» Opposite of manual memory management
» Used to free unused allocated memory
» Can handle more types of resources (network
sockets, database handlers, …) using finalization
and region-based allocation
12
The garbage collection
» No dangling pointers
» No memory leaks
» No double free
» Can reduce performances
» Stop-the-world issues
» Can be unpredictable
13
Two types of garbage
collector
Reference counting
How reference counting is implemented?
» Each object has a count of other objects
referencing it
» An object is considered as garbage when its
counter reach 0
16
How reference counting is implemented? 17
How reference counting is implemented? 18
Disadvantages of reference counting
» Sensitive to cycle referencing
19
Disadvantages of reference counting
» Increased space overhead
» Must be atomic
» Not real-time
20
Tracing garbage collection
Concept of tracing garbage collection
» Determine which objects are reachable from a
certain “root” object
» Unreachable objects are considered as garbage
» Can use a lot of algorithms
22
Two ways of reachability
» The object is reachable from a certain root
» Local variables
» Parameters
» Global variables
» The object is reachable via another reachable
object
23
Tracing garbage collection
The naïve mark-and-sweep algorithm
The naïve mark-and-sweep algorithm
» Two stages algorithm
» First, run through the root set tree and mark
reachable objects
» Second, run through the whole memory, sweep
unmarked objects and clear mark of marked
objects
25
The naïve mark-and-sweep algorithm disadvantages
» Must run through the memory twice
» Must freeze the execution of the program to avoid
mutation of the working set
26
Go and the garbage collection
The tri-color marking
The tri-color marking
» Proposed by Dijkstra in 1978
» Tri-color
» Concurrent
» Mark-and-sweep
28
The tri-color marking concept
» Heap is a graph of connected objects
» Uses 3 colored sets
» White: contains objects to collect
» Gray: contains objects reachable from the root
but not yet scanned
» Black: contains reachable and scanned objects
29
The tri-color marking steps
» At the beginning, everyone is in the white set
» Root objects are moved in the gray set
» A root object is scanned
» Its references are colored gray, while the root object itself is
colored black
» Its references are scanned too and moved to the black set
» Once the gray set is empty, the remaining objects in the white set
are freed and sets are recolored
30
The tri-color marking by example 31
The tri-color marking by example 32
The tri-color marking by example 33
The tri-color marking by example 34
The tri-color marking by example 35
The tri-color marking by example 36
The tri-color marking by example 37
The algorithm invariant
“The tri-color marking invariant
No black object may contain a pointer to a
white object
39
How to always satisfy the invariant?
» Stop the world until GC is complete
» Use a write barrier
» Function executed by the mutator to tell the GC that a pointer
has been changed
» Enforce an object to be gray when it is created during the
garbage collector cycle
40
How to always satisfy the invariant? 41
Go back to lower versions of Go
The garbage collector review by Richard Hudson
Go 1.4 and lower
» Stop-the-world from the beginning of the cycle to
the end
» High GC latency
» Not concurrent
43
Go 1.5 (and actual) garbage collector
» Made by Richard Hudson and his team
» Concurrent
» Low latency
» Decrease program performances but increase
throughput
44
Go 1.5 new garbage collector 45
Benchmarking 46
Go 1.6 and further
» Improvements on when to start a GC cycle, used
metrics, etc.
» Predictive
47
What’s new in Go 1.8?
The garbage collector review
Actual garbage collector pain point 49
New type of write barrier
» Hybrid write barrier
» Dijkstra (1978)
» Yuasa (1990)
» New algorithm invariant (weak invariant)
» No need to rescan the whole memory
» Reduces GC cycle
» 100 microseconds for the worst case
» 50 microseconds for 95 percentile
50
“
Any white object pointed to by a black object
is reachable from a grey object via a chain of
white pointers (it is grey-protected).
51
Go 1.8 hybrid write barrier 52
Languages without garbage
collector
Rust
» Based on ownership and borrowing
» Every value has a scope
» Passing or returning a value means transferring its ownership
» When a scope ends, owned values are destroyed
» Everything is checked at compile time
» Everything is allocated on the stack by default
» Using stack frames
» Stack frames are freed on function return
» Can be allocated on the heap using boxes
54
Rust - Ownership 55
Rust - Ownership 56
Rust - Ownership 57
Rust - Borrowing 58
“
Thank you for listening
59
References
» Pusher https://blog.pusher.com/golangs-real-time-gc-in-theory-and-practice/
» Golang new GC proposal
https://github.com/golang/proposal/blob/master/design/17503-eliminate-rescan.md
» Go GC 1.5 blog post https://blog.golang.org/go15gc
» GopherCon 2015 GC Latency talk https://www.youtube.com/watch?v=aiv1JOfMjm0
» Dijkstra 1978 GC paper http://dl.acm.org/citation.cfm?id=359655
» Rust lang https://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.html
60

More Related Content

What's hot

Request routing in CDN
Request routing in CDNRequest routing in CDN
Request routing in CDNSandeep Kath
 
Introduction To RabbitMQ
Introduction To RabbitMQIntroduction To RabbitMQ
Introduction To RabbitMQKnoldus Inc.
 
Multicast Routing Protocols
Multicast Routing ProtocolsMulticast Routing Protocols
Multicast Routing ProtocolsRam Dutt Shukla
 
RPL - Routing Protocol for Low Power and Lossy Networks
RPL - Routing Protocol for Low Power and Lossy NetworksRPL - Routing Protocol for Low Power and Lossy Networks
RPL - Routing Protocol for Low Power and Lossy NetworksPradeep Kumar TS
 
Introduction to Computer Communication M1
Introduction to Computer Communication  M1Introduction to Computer Communication  M1
Introduction to Computer Communication M1DrSSwapnaKumar
 
OSMC 2022 | The Power of Metrics, Logs & Traces with Open Source by Emil-Andr...
OSMC 2022 | The Power of Metrics, Logs & Traces with Open Source by Emil-Andr...OSMC 2022 | The Power of Metrics, Logs & Traces with Open Source by Emil-Andr...
OSMC 2022 | The Power of Metrics, Logs & Traces with Open Source by Emil-Andr...NETWAYS
 
Distance Vector Multicast Routing Protocol (DVMRP) : Presentation
Distance Vector Multicast Routing Protocol (DVMRP) : PresentationDistance Vector Multicast Routing Protocol (DVMRP) : Presentation
Distance Vector Multicast Routing Protocol (DVMRP) : PresentationSubhajit Sahu
 
An overview of TCP (Transmission Control Protocol)
An overview of TCP (Transmission Control Protocol)An overview of TCP (Transmission Control Protocol)
An overview of TCP (Transmission Control Protocol)Ammad Marwat
 
The Road to End-to-End Encryption in Jitsi Meet
The Road to End-to-End Encryption in Jitsi MeetThe Road to End-to-End Encryption in Jitsi Meet
The Road to End-to-End Encryption in Jitsi MeetSaúl Ibarra Corretgé
 
Routing and routing algorithms
Routing and routing algorithmsRouting and routing algorithms
Routing and routing algorithmsBhatt Aadil
 
Sliding window
 Sliding window Sliding window
Sliding windowradhaswam
 
LMAX Disruptor as real-life example
LMAX Disruptor as real-life exampleLMAX Disruptor as real-life example
LMAX Disruptor as real-life exampleGuy Nir
 
Firewall Design and Implementation
Firewall Design and ImplementationFirewall Design and Implementation
Firewall Design and Implementationajeet singh
 
Bits of Evidence
Bits of EvidenceBits of Evidence
Bits of EvidenceGreg Wilson
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithmBushra M
 

What's hot (20)

Request routing in CDN
Request routing in CDNRequest routing in CDN
Request routing in CDN
 
Introduction To RabbitMQ
Introduction To RabbitMQIntroduction To RabbitMQ
Introduction To RabbitMQ
 
Quality of Service
Quality of ServiceQuality of Service
Quality of Service
 
Cache optimization
Cache optimizationCache optimization
Cache optimization
 
Multicast Routing Protocols
Multicast Routing ProtocolsMulticast Routing Protocols
Multicast Routing Protocols
 
RPL - Routing Protocol for Low Power and Lossy Networks
RPL - Routing Protocol for Low Power and Lossy NetworksRPL - Routing Protocol for Low Power and Lossy Networks
RPL - Routing Protocol for Low Power and Lossy Networks
 
IP Multicasting
IP MulticastingIP Multicasting
IP Multicasting
 
Introduction to Computer Communication M1
Introduction to Computer Communication  M1Introduction to Computer Communication  M1
Introduction to Computer Communication M1
 
OSMC 2022 | The Power of Metrics, Logs & Traces with Open Source by Emil-Andr...
OSMC 2022 | The Power of Metrics, Logs & Traces with Open Source by Emil-Andr...OSMC 2022 | The Power of Metrics, Logs & Traces with Open Source by Emil-Andr...
OSMC 2022 | The Power of Metrics, Logs & Traces with Open Source by Emil-Andr...
 
Distance Vector Multicast Routing Protocol (DVMRP) : Presentation
Distance Vector Multicast Routing Protocol (DVMRP) : PresentationDistance Vector Multicast Routing Protocol (DVMRP) : Presentation
Distance Vector Multicast Routing Protocol (DVMRP) : Presentation
 
An overview of TCP (Transmission Control Protocol)
An overview of TCP (Transmission Control Protocol)An overview of TCP (Transmission Control Protocol)
An overview of TCP (Transmission Control Protocol)
 
The Road to End-to-End Encryption in Jitsi Meet
The Road to End-to-End Encryption in Jitsi MeetThe Road to End-to-End Encryption in Jitsi Meet
The Road to End-to-End Encryption in Jitsi Meet
 
Routing and routing algorithms
Routing and routing algorithmsRouting and routing algorithms
Routing and routing algorithms
 
Sliding window
 Sliding window Sliding window
Sliding window
 
LMAX Disruptor as real-life example
LMAX Disruptor as real-life exampleLMAX Disruptor as real-life example
LMAX Disruptor as real-life example
 
Routing Protocols
Routing ProtocolsRouting Protocols
Routing Protocols
 
Firewall Design and Implementation
Firewall Design and ImplementationFirewall Design and Implementation
Firewall Design and Implementation
 
Bits of Evidence
Bits of EvidenceBits of Evidence
Bits of Evidence
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithm
 
Replication in Distributed Systems
Replication in Distributed SystemsReplication in Distributed Systems
Replication in Distributed Systems
 

Similar to Go and the garbage collection

JDK8 Functional API
JDK8 Functional APIJDK8 Functional API
JDK8 Functional APIJustin Lin
 
.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup 7 - CLR Memory by Fabian Alves.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup 7 - CLR Memory by Fabian Alves.NET UY Meetup
 
A survey on Heap Exploitation
A survey on Heap Exploitation A survey on Heap Exploitation
A survey on Heap Exploitation Alireza Karimi
 
Probabilistic data structure
Probabilistic data structureProbabilistic data structure
Probabilistic data structureThinh Dang
 
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)Sung Kim
 
Yin Yangs of Software Development
Yin Yangs of Software DevelopmentYin Yangs of Software Development
Yin Yangs of Software DevelopmentNaveenkumar Muguda
 
Introduction to Big Data
Introduction to Big DataIntroduction to Big Data
Introduction to Big DataAlbert Bifet
 
Reactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayReactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayRoland Kuhn
 
Ants coony optimiztion problem in Advance analysis of algorithms
Ants coony optimiztion problem in Advance analysis of algorithmsAnts coony optimiztion problem in Advance analysis of algorithms
Ants coony optimiztion problem in Advance analysis of algorithmsALIZAIB KHAN
 
Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford MapR Technologies
 
Big Graph Analytics Systems (Sigmod16 Tutorial)
Big Graph Analytics Systems (Sigmod16 Tutorial)Big Graph Analytics Systems (Sigmod16 Tutorial)
Big Graph Analytics Systems (Sigmod16 Tutorial)Yuanyuan Tian
 
Garbage Collection
Garbage CollectionGarbage Collection
Garbage CollectionEelco Visser
 
Aco 03-04-2013
Aco 03-04-2013Aco 03-04-2013
Aco 03-04-2013Ahmad Khan
 
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...huguk
 
Tutorial 9 (bloom filters)
Tutorial 9 (bloom filters)Tutorial 9 (bloom filters)
Tutorial 9 (bloom filters)Kira
 

Similar to Go and the garbage collection (20)

JDK8 Functional API
JDK8 Functional APIJDK8 Functional API
JDK8 Functional API
 
.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup 7 - CLR Memory by Fabian Alves.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup 7 - CLR Memory by Fabian Alves
 
Understanding low latency jvm gcs
Understanding low latency jvm gcsUnderstanding low latency jvm gcs
Understanding low latency jvm gcs
 
A survey on Heap Exploitation
A survey on Heap Exploitation A survey on Heap Exploitation
A survey on Heap Exploitation
 
Probabilistic data structure
Probabilistic data structureProbabilistic data structure
Probabilistic data structure
 
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
 
Yin Yangs of Software Development
Yin Yangs of Software DevelopmentYin Yangs of Software Development
Yin Yangs of Software Development
 
Introduction to Big Data
Introduction to Big DataIntroduction to Big Data
Introduction to Big Data
 
Hoard_2022AIM1001.pptx.pdf
Hoard_2022AIM1001.pptx.pdfHoard_2022AIM1001.pptx.pdf
Hoard_2022AIM1001.pptx.pdf
 
Reactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayReactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive Way
 
Ants coony optimiztion problem in Advance analysis of algorithms
Ants coony optimiztion problem in Advance analysis of algorithmsAnts coony optimiztion problem in Advance analysis of algorithms
Ants coony optimiztion problem in Advance analysis of algorithms
 
Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford
 
C# basics
C# basicsC# basics
C# basics
 
Quantum Computing
Quantum ComputingQuantum Computing
Quantum Computing
 
Big Graph Analytics Systems (Sigmod16 Tutorial)
Big Graph Analytics Systems (Sigmod16 Tutorial)Big Graph Analytics Systems (Sigmod16 Tutorial)
Big Graph Analytics Systems (Sigmod16 Tutorial)
 
Garbage Collection
Garbage CollectionGarbage Collection
Garbage Collection
 
Aco 03-04-2013
Aco 03-04-2013Aco 03-04-2013
Aco 03-04-2013
 
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
 
Lecture_3.pptx
Lecture_3.pptxLecture_3.pptx
Lecture_3.pptx
 
Tutorial 9 (bloom filters)
Tutorial 9 (bloom filters)Tutorial 9 (bloom filters)
Tutorial 9 (bloom filters)
 

Recently uploaded

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Recently uploaded (20)

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

Go and the garbage collection

  • 1. Go & The garbage collection
  • 2. “ Joris Bonnefoy DevOps @ OVH @devatoria 2
  • 3. Introduction Reminder of basic algorithmic structures
  • 4. » Objects have a pointer to the next element of the list » The last element have a null pointer Linked list 4
  • 5. » Objects have pointers to the next and the previous element of the list » The first element have a null previous pointer » The last element have a null next pointer Doubly linked list 5
  • 6. » Objects have pointers to the next and the previous element of the list » The first element have a previous pointer to the last element of the list » The last element have a next pointer to the first element of the list Circular doubly linked list 6
  • 7. A simple problem How to free a dereferenced object?
  • 8. How to free a dereferenced object? 8
  • 9. How to free a dereferenced object? 9
  • 10. How to free a dereferenced object? 10
  • 12. The garbage collection » John McCarthy - 1959 - Lisp » Opposite of manual memory management » Used to free unused allocated memory » Can handle more types of resources (network sockets, database handlers, …) using finalization and region-based allocation 12
  • 13. The garbage collection » No dangling pointers » No memory leaks » No double free » Can reduce performances » Stop-the-world issues » Can be unpredictable 13
  • 14. Two types of garbage collector
  • 16. How reference counting is implemented? » Each object has a count of other objects referencing it » An object is considered as garbage when its counter reach 0 16
  • 17. How reference counting is implemented? 17
  • 18. How reference counting is implemented? 18
  • 19. Disadvantages of reference counting » Sensitive to cycle referencing 19
  • 20. Disadvantages of reference counting » Increased space overhead » Must be atomic » Not real-time 20
  • 22. Concept of tracing garbage collection » Determine which objects are reachable from a certain “root” object » Unreachable objects are considered as garbage » Can use a lot of algorithms 22
  • 23. Two ways of reachability » The object is reachable from a certain root » Local variables » Parameters » Global variables » The object is reachable via another reachable object 23
  • 24. Tracing garbage collection The naïve mark-and-sweep algorithm
  • 25. The naïve mark-and-sweep algorithm » Two stages algorithm » First, run through the root set tree and mark reachable objects » Second, run through the whole memory, sweep unmarked objects and clear mark of marked objects 25
  • 26. The naïve mark-and-sweep algorithm disadvantages » Must run through the memory twice » Must freeze the execution of the program to avoid mutation of the working set 26
  • 27. Go and the garbage collection The tri-color marking
  • 28. The tri-color marking » Proposed by Dijkstra in 1978 » Tri-color » Concurrent » Mark-and-sweep 28
  • 29. The tri-color marking concept » Heap is a graph of connected objects » Uses 3 colored sets » White: contains objects to collect » Gray: contains objects reachable from the root but not yet scanned » Black: contains reachable and scanned objects 29
  • 30. The tri-color marking steps » At the beginning, everyone is in the white set » Root objects are moved in the gray set » A root object is scanned » Its references are colored gray, while the root object itself is colored black » Its references are scanned too and moved to the black set » Once the gray set is empty, the remaining objects in the white set are freed and sets are recolored 30
  • 31. The tri-color marking by example 31
  • 32. The tri-color marking by example 32
  • 33. The tri-color marking by example 33
  • 34. The tri-color marking by example 34
  • 35. The tri-color marking by example 35
  • 36. The tri-color marking by example 36
  • 37. The tri-color marking by example 37
  • 39. “The tri-color marking invariant No black object may contain a pointer to a white object 39
  • 40. How to always satisfy the invariant? » Stop the world until GC is complete » Use a write barrier » Function executed by the mutator to tell the GC that a pointer has been changed » Enforce an object to be gray when it is created during the garbage collector cycle 40
  • 41. How to always satisfy the invariant? 41
  • 42. Go back to lower versions of Go The garbage collector review by Richard Hudson
  • 43. Go 1.4 and lower » Stop-the-world from the beginning of the cycle to the end » High GC latency » Not concurrent 43
  • 44. Go 1.5 (and actual) garbage collector » Made by Richard Hudson and his team » Concurrent » Low latency » Decrease program performances but increase throughput 44
  • 45. Go 1.5 new garbage collector 45
  • 47. Go 1.6 and further » Improvements on when to start a GC cycle, used metrics, etc. » Predictive 47
  • 48. What’s new in Go 1.8? The garbage collector review
  • 49. Actual garbage collector pain point 49
  • 50. New type of write barrier » Hybrid write barrier » Dijkstra (1978) » Yuasa (1990) » New algorithm invariant (weak invariant) » No need to rescan the whole memory » Reduces GC cycle » 100 microseconds for the worst case » 50 microseconds for 95 percentile 50
  • 51. “ Any white object pointed to by a black object is reachable from a grey object via a chain of white pointers (it is grey-protected). 51
  • 52. Go 1.8 hybrid write barrier 52
  • 54. Rust » Based on ownership and borrowing » Every value has a scope » Passing or returning a value means transferring its ownership » When a scope ends, owned values are destroyed » Everything is checked at compile time » Everything is allocated on the stack by default » Using stack frames » Stack frames are freed on function return » Can be allocated on the heap using boxes 54
  • 59. “ Thank you for listening 59
  • 60. References » Pusher https://blog.pusher.com/golangs-real-time-gc-in-theory-and-practice/ » Golang new GC proposal https://github.com/golang/proposal/blob/master/design/17503-eliminate-rescan.md » Go GC 1.5 blog post https://blog.golang.org/go15gc » GopherCon 2015 GC Latency talk https://www.youtube.com/watch?v=aiv1JOfMjm0 » Dijkstra 1978 GC paper http://dl.acm.org/citation.cfm?id=359655 » Rust lang https://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.html 60