SlideShare a Scribd company logo
1 of 31
Download to read offline
SAFE GO
GOTHENBURG, SWEDEN, OCT 26 2022
Max Ekman
Software Engineer
Einride
“Look ma! No hands!”
A Gopher in an autonomous vehicle? 01
The case for Safe Go
Unsafe code situations
Do’s and don’ts
Safe Go style guide
Questions?
02
03
04
05
06
A Gopher in an
autonomous
vehicle?
SECTION ONE
{
WHY A GOPHER THERE IN THE FIRST PLACE?
Simplicity.
Even “hard” AD
development
should be easy
to approach.
01. A GOPHER IN AN AUTONOMOUS VEHICLE
{
WHY A GOPHER THERE IN THE FIRST PLACE?
Commonality.
Engineers
should be able
to jump teams:
AD vs cloud.
01. A GOPHER IN AN AUTONOMOUS VEHICLE
{
WHY A GOPHER THERE IN THE FIRST PLACE?
Ecosystem.
Go has a huge open
source ecosystem.
Einride is part of it!
01. A GOPHER IN AN AUTONOMOUS VEHICLE
The case for
Safe Go
SECTION TWO
03
Can Go be used in a
mixed criticality system?
CAN GO BE USED IN A SAFETY CRITICAL ENVIRONMENT?
02. THE CASE FOR SAFE GO
02
03
We think yes!
But with the right
approach and tooling.
CAN GO BE USED IN A SAFETY CRITICAL ENVIRONMENT?
02. THE CASE FOR SAFE GO
02
Differences to “common” Go development
03. THE CASE FOR SAFE GO
● Long running processes - not req/resp
● Resource constrained environment
● “Soft” realtime requirements
● Debug challanges
● Requirements of high correctness
Unsafe code
situations
SECTION THREE
EXAMPLES OF UNSAFE CODE SITUATIONS
03. UNSAFE CODE SITUATIONS
🧮 Unbounded memory usage
🧠 Unbounded concurrency
⏱ Garbage collection latency
🔄 Synchronization and deadlocks
🧮 UNBOUNDED MEMORY USAGE
03. UNSAFE CODE SITUATIONS
● Occurs when allocating during iterations:
loops, recursions, net RX etc
● Negatively impacts:
○ Resource usage
○ GC load
○ Heap fragmentation
🧠 UNBOUNDED CONCURRENCY
03. UNSAFE CODE SITUATIONS
● Occurs when spawning goroutines during
iterations: loops, recursions, net RX etc
● Negatively impacts:
○ Runtime context switching
○ OS thread context switching
○ Goroutine heap allocations
⏱ GARBAGE COLLECTION LATENCY
03. UNSAFE CODE SITUATIONS
● Occurs when there are many deallocations:
functions returns, variables out of scope etc
● Negatively impacts:
○ Time spent in runtime vs user code
○ CPU context switching waste
🔄 SYNCHRONIZATION AND DEADLOCKS
03. UNSAFE CODE SITUATIONS
● Deadlocks can be a big problem when trying
to synchronize concurrent code
● Negatively impacts:
○ Less throughput
○ Leads to hard-to-find bugs
Do’s and
don’ts
SECTION FOUR
🧮 UNBOUNDED MEMORY USAGE
04. DO’S AND DON’TS
Watch out for append() inside loops, especially when the input length is unknown
Don’t…
🧮 UNBOUNDED MEMORY USAGE
04. DO’S AND DON’TS
Instead try to preallocate any slices to a given capacity
Do!
🧠 UNBOUNDED CONCURRENCY
04. DO’S AND DON’TS
Don’t start goroutines in a loop without checking the length of the input
Don’t…
🧠 UNBOUNDED CONCURRENCY
04. DO’S AND DON’TS
Instead spawn a known amount of “workers” and pass them the input.
Do! But use something
robust, like errgroup!
⏱ GARBAGE COLLECTION LATENCY
04. DO’S AND DON’TS
Allocs can happen where you least expect it. Dig into the code to find out!
Don’t…
⏱ GARBAGE COLLECTION LATENCY
04. DO’S AND DON’TS
In this case strings.Count() was enough, which doesn’t alloc anything.
Do!
🔄 SYNCHRONIZATION AND DEADLOCKS
04. DO’S AND DON’TS
Watch out when getting access to references, mutexes doesn’t help here.
Don’t…
🔄 SYNCHRONIZATION AND DEADLOCKS
04. DO’S AND DON’TS
Instead copy data inside locked section, if needed outside.
Do!
🍑
ROB PIKE
Don't communicate by
sharing memory,
share memory by
communicating.
go-proverbs.github.io
Safe Go
style guide
and tooling
SECTION FIVE
01
Watch this space!
einride.engineering/blog
github.com/einride
05. SAFE GO STYLE GUIDE
THE NEED FOR A STYLE GUIDE
05
Official docs rulez!
go.dev/doc/effective_go
go.dev/doc/gc-guide
go.dev/doc/diagnostics
Another good guide:
peter.bourgon.org/go-for-industrial-programming
OTHER RESOURCES
Questions?
And thanks!
SECTION SIX

More Related Content

Similar to Safe Go - 2022-10-26 - Go West

Javascript Programming according to Industry Standards.pptx
Javascript Programming according to Industry Standards.pptxJavascript Programming according to Industry Standards.pptx
Javascript Programming according to Industry Standards.pptxMukundSonaiya1
 
Web technologies-course 08.pptx
Web technologies-course 08.pptxWeb technologies-course 08.pptx
Web technologies-course 08.pptxStefan Oprea
 
SaltConf 2014: Safety with powertools
SaltConf 2014: Safety with powertoolsSaltConf 2014: Safety with powertools
SaltConf 2014: Safety with powertoolsThomas Jackson
 
The benefits of running Spark on your own Docker
The benefits of running Spark on your own DockerThe benefits of running Spark on your own Docker
The benefits of running Spark on your own DockerItai Yaffe
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2Knoldus Inc.
 
PyCon Canada 2019 - Introduction to Asynchronous Programming
PyCon Canada 2019 - Introduction to Asynchronous ProgrammingPyCon Canada 2019 - Introduction to Asynchronous Programming
PyCon Canada 2019 - Introduction to Asynchronous ProgrammingJuti Noppornpitak
 
Of innovation and impatience - Future Decoded 2015
Of innovation and impatience - Future Decoded 2015Of innovation and impatience - Future Decoded 2015
Of innovation and impatience - Future Decoded 2015Christian Heilmann
 
Serverless for High Performance Computing
Serverless for High Performance ComputingServerless for High Performance Computing
Serverless for High Performance ComputingLuciano Mammino
 
Code Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif IqbalCode Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif IqbalCefalo
 
Hexagonal Architecture.pdf
Hexagonal Architecture.pdfHexagonal Architecture.pdf
Hexagonal Architecture.pdfVladimirRadzivil
 
Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!
Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!
Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!Anne Nicolas
 
Serverless? How (not) to develop, deploy and operate serverless applications.
Serverless? How (not) to develop, deploy and operate serverless applications.Serverless? How (not) to develop, deploy and operate serverless applications.
Serverless? How (not) to develop, deploy and operate serverless applications.gjdevos
 
New Repository in AEM 6 by Michael Marth
New Repository in AEM 6 by Michael MarthNew Repository in AEM 6 by Michael Marth
New Repository in AEM 6 by Michael MarthAEM HUB
 
Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...
Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...
Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...Gáspár Nagy
 

Similar to Safe Go - 2022-10-26 - Go West (20)

Javascript Programming according to Industry Standards.pptx
Javascript Programming according to Industry Standards.pptxJavascript Programming according to Industry Standards.pptx
Javascript Programming according to Industry Standards.pptx
 
Web technologies-course 08.pptx
Web technologies-course 08.pptxWeb technologies-course 08.pptx
Web technologies-course 08.pptx
 
How not program in c
How not program in cHow not program in c
How not program in c
 
SaltConf 2014: Safety with powertools
SaltConf 2014: Safety with powertoolsSaltConf 2014: Safety with powertools
SaltConf 2014: Safety with powertools
 
The benefits of running Spark on your own Docker
The benefits of running Spark on your own DockerThe benefits of running Spark on your own Docker
The benefits of running Spark on your own Docker
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
 
PyCon Canada 2019 - Introduction to Asynchronous Programming
PyCon Canada 2019 - Introduction to Asynchronous ProgrammingPyCon Canada 2019 - Introduction to Asynchronous Programming
PyCon Canada 2019 - Introduction to Asynchronous Programming
 
Of innovation and impatience - Future Decoded 2015
Of innovation and impatience - Future Decoded 2015Of innovation and impatience - Future Decoded 2015
Of innovation and impatience - Future Decoded 2015
 
Serverless for High Performance Computing
Serverless for High Performance ComputingServerless for High Performance Computing
Serverless for High Performance Computing
 
Code Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif IqbalCode Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif Iqbal
 
An introduction to programming in Go
An introduction to programming in GoAn introduction to programming in Go
An introduction to programming in Go
 
Hexagonal Architecture.pdf
Hexagonal Architecture.pdfHexagonal Architecture.pdf
Hexagonal Architecture.pdf
 
12 tricks to avoid hackers breaks your CI / CD
12 tricks to avoid hackers breaks your  CI / CD12 tricks to avoid hackers breaks your  CI / CD
12 tricks to avoid hackers breaks your CI / CD
 
Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!
Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!
Kernel Recipes 2014 - Writing Code: Keep It Short, Stupid!
 
Surveillance on slam technology
Surveillance on slam technologySurveillance on slam technology
Surveillance on slam technology
 
Hexagonal architecture
Hexagonal architectureHexagonal architecture
Hexagonal architecture
 
Serverless? How (not) to develop, deploy and operate serverless applications.
Serverless? How (not) to develop, deploy and operate serverless applications.Serverless? How (not) to develop, deploy and operate serverless applications.
Serverless? How (not) to develop, deploy and operate serverless applications.
 
New Repository in AEM 6 by Michael Marth
New Repository in AEM 6 by Michael MarthNew Repository in AEM 6 by Michael Marth
New Repository in AEM 6 by Michael Marth
 
Unit testing hippo
Unit testing hippoUnit testing hippo
Unit testing hippo
 
Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...
Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...
Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...
 

Recently uploaded

Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...software pro Development
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 

Recently uploaded (20)

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 

Safe Go - 2022-10-26 - Go West

  • 1. SAFE GO GOTHENBURG, SWEDEN, OCT 26 2022 Max Ekman Software Engineer Einride
  • 2. “Look ma! No hands!” A Gopher in an autonomous vehicle? 01 The case for Safe Go Unsafe code situations Do’s and don’ts Safe Go style guide Questions? 02 03 04 05 06
  • 3. A Gopher in an autonomous vehicle? SECTION ONE
  • 4. { WHY A GOPHER THERE IN THE FIRST PLACE? Simplicity. Even “hard” AD development should be easy to approach. 01. A GOPHER IN AN AUTONOMOUS VEHICLE
  • 5. { WHY A GOPHER THERE IN THE FIRST PLACE? Commonality. Engineers should be able to jump teams: AD vs cloud. 01. A GOPHER IN AN AUTONOMOUS VEHICLE
  • 6. { WHY A GOPHER THERE IN THE FIRST PLACE? Ecosystem. Go has a huge open source ecosystem. Einride is part of it! 01. A GOPHER IN AN AUTONOMOUS VEHICLE
  • 7. The case for Safe Go SECTION TWO
  • 8. 03 Can Go be used in a mixed criticality system? CAN GO BE USED IN A SAFETY CRITICAL ENVIRONMENT? 02. THE CASE FOR SAFE GO 02
  • 9. 03 We think yes! But with the right approach and tooling. CAN GO BE USED IN A SAFETY CRITICAL ENVIRONMENT? 02. THE CASE FOR SAFE GO 02
  • 10. Differences to “common” Go development 03. THE CASE FOR SAFE GO ● Long running processes - not req/resp ● Resource constrained environment ● “Soft” realtime requirements ● Debug challanges ● Requirements of high correctness
  • 12. EXAMPLES OF UNSAFE CODE SITUATIONS 03. UNSAFE CODE SITUATIONS 🧮 Unbounded memory usage 🧠 Unbounded concurrency ⏱ Garbage collection latency 🔄 Synchronization and deadlocks
  • 13. 🧮 UNBOUNDED MEMORY USAGE 03. UNSAFE CODE SITUATIONS ● Occurs when allocating during iterations: loops, recursions, net RX etc ● Negatively impacts: ○ Resource usage ○ GC load ○ Heap fragmentation
  • 14. 🧠 UNBOUNDED CONCURRENCY 03. UNSAFE CODE SITUATIONS ● Occurs when spawning goroutines during iterations: loops, recursions, net RX etc ● Negatively impacts: ○ Runtime context switching ○ OS thread context switching ○ Goroutine heap allocations
  • 15. ⏱ GARBAGE COLLECTION LATENCY 03. UNSAFE CODE SITUATIONS ● Occurs when there are many deallocations: functions returns, variables out of scope etc ● Negatively impacts: ○ Time spent in runtime vs user code ○ CPU context switching waste
  • 16. 🔄 SYNCHRONIZATION AND DEADLOCKS 03. UNSAFE CODE SITUATIONS ● Deadlocks can be a big problem when trying to synchronize concurrent code ● Negatively impacts: ○ Less throughput ○ Leads to hard-to-find bugs
  • 18. 🧮 UNBOUNDED MEMORY USAGE 04. DO’S AND DON’TS Watch out for append() inside loops, especially when the input length is unknown Don’t…
  • 19. 🧮 UNBOUNDED MEMORY USAGE 04. DO’S AND DON’TS Instead try to preallocate any slices to a given capacity Do!
  • 20. 🧠 UNBOUNDED CONCURRENCY 04. DO’S AND DON’TS Don’t start goroutines in a loop without checking the length of the input Don’t…
  • 21. 🧠 UNBOUNDED CONCURRENCY 04. DO’S AND DON’TS Instead spawn a known amount of “workers” and pass them the input. Do! But use something robust, like errgroup!
  • 22. ⏱ GARBAGE COLLECTION LATENCY 04. DO’S AND DON’TS Allocs can happen where you least expect it. Dig into the code to find out! Don’t…
  • 23. ⏱ GARBAGE COLLECTION LATENCY 04. DO’S AND DON’TS In this case strings.Count() was enough, which doesn’t alloc anything. Do!
  • 24. 🔄 SYNCHRONIZATION AND DEADLOCKS 04. DO’S AND DON’TS Watch out when getting access to references, mutexes doesn’t help here. Don’t…
  • 25. 🔄 SYNCHRONIZATION AND DEADLOCKS 04. DO’S AND DON’TS Instead copy data inside locked section, if needed outside. Do!
  • 26. 🍑
  • 27. ROB PIKE Don't communicate by sharing memory, share memory by communicating. go-proverbs.github.io
  • 28. Safe Go style guide and tooling SECTION FIVE
  • 29. 01 Watch this space! einride.engineering/blog github.com/einride 05. SAFE GO STYLE GUIDE THE NEED FOR A STYLE GUIDE 05
  • 30. Official docs rulez! go.dev/doc/effective_go go.dev/doc/gc-guide go.dev/doc/diagnostics Another good guide: peter.bourgon.org/go-for-industrial-programming OTHER RESOURCES