Top Banner
Seen by a C++ developer The low-level awesomeness of Go
24

The low level awesomeness of Go

Apr 16, 2017

Download

Engineering

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The low level awesomeness of Go

SeenbyaC++developer

Thelow-levelawesomenessofGo

Page 2: The low level awesomeness of Go

ConcurrentI/OprogramminginC++

Page 3: The low level awesomeness of Go

ConcurrentI/OprogramminginC++

Complicated:Programintentdilutedintosynchronizationtooling(threads,

mutexes,eventloops).

Page 4: The low level awesomeness of Go

ConcurrentI/OprogramminginC++

Verbose:Alotofcodetowritetodosimplethings.

Page 5: The low level awesomeness of Go

ConcurrentI/OprogramminginC++

Delicate:Onestepoutofthewayandyoublowthewholethingup.

Page 6: The low level awesomeness of Go

WhyGoappealsC++developers

Page 7: The low level awesomeness of Go

WhyGoappealsC++developers

Goroutines:Breakthecodeintologicalparts

Page 8: The low level awesomeness of Go

WhyGoappealsC++developers

I/Ofriendly:Netpollerfreesthedeveloperfrominfamouscallbacks

Page 9: The low level awesomeness of Go

WhyGoappealsC++developers

Codeasdataflow:Channelsmakesiteasytowriteapplicationasadata

pipeline

Page 10: The low level awesomeness of Go

Goroutines:howdoesitdoit

Page 11: The low level awesomeness of Go

Goroutines:howdoesitdoit

GoiswritteninassemblyandGoexclusively(exceptforcgo).

ASMcode

Page 12: The low level awesomeness of Go

Goroutines:howdoesitdoit

Jumpingtheexecutionflowbetweenagoroutineandtheschedulerisfast

Fastcontextswitching

Page 13: The low level awesomeness of Go

Process/Thread 3000to4500nsCPUAffinity 1300to1900nsCPUAffinity

Goroutine:<10ns

Goroutines:howdoesitdoitFastcontextswitching

Page 14: The low level awesomeness of Go

Goroutines:howdoesitdoit

TLSisusedtojumpfromaGoroutinetothescheduler

ClassicTLScanbecostlydependingontheplatform

ThreadLocalStorage

Page 15: The low level awesomeness of Go

Goroutines:howdoesitdoit

GotakesadvantageofaunusedMMUregistryifpossible

ThreadLocalStorage

Page 16: The low level awesomeness of Go

Netpoller:howdoesitdoit

Page 17: The low level awesomeness of Go

Netpoller:howdoesitdoit

TheschedulerunparksGoroutinesjustwhenI/Oisavailable.

Hiddeninthescheduler

Page 18: The low level awesomeness of Go

Netpoller:howdoesitdoit

epollforLinux

kqueueforMacOS

I/OCompletionportsforWindows

SyscallsdependingontheOS

Page 19: The low level awesomeness of Go

Channels:howdoesitdoit

Page 20: The low level awesomeness of Go

Channels:howdoesitdoit

Lock-freeforawriterinanon-fullchannel.

Lock-freeforareaderinanon-emptychannel.

Criticalsectionstaysshortforblockingcalls.

Limitedusageofmutexes

Page 21: The low level awesomeness of Go

Channels:howdoesitdoit

Lock-freeoperationsuseatomicCopyAndSwapformodernprocessors

Atomics

Page 22: The low level awesomeness of Go

Channels:howdoesitdoit

Gomutexesareimplementedwithfutexes(FastUserspacemuTEX).

Fastmutexes

Page 23: The low level awesomeness of Go

duckie.github.io/boson

SeethosethingsimplementedinC++

Page 24: The low level awesomeness of Go

Thankyouverymuch