The low level awesomeness of Go

Preview:

Citation preview

SeenbyaC++developer

Thelow-levelawesomenessofGo

ConcurrentI/OprogramminginC++

ConcurrentI/OprogramminginC++

Complicated:Programintentdilutedintosynchronizationtooling(threads,

mutexes,eventloops).

ConcurrentI/OprogramminginC++

Verbose:Alotofcodetowritetodosimplethings.

ConcurrentI/OprogramminginC++

Delicate:Onestepoutofthewayandyoublowthewholethingup.

WhyGoappealsC++developers

WhyGoappealsC++developers

Goroutines:Breakthecodeintologicalparts

WhyGoappealsC++developers

I/Ofriendly:Netpollerfreesthedeveloperfrominfamouscallbacks

WhyGoappealsC++developers

Codeasdataflow:Channelsmakesiteasytowriteapplicationasadata

pipeline

Goroutines:howdoesitdoit

Goroutines:howdoesitdoit

GoiswritteninassemblyandGoexclusively(exceptforcgo).

ASMcode

Goroutines:howdoesitdoit

Jumpingtheexecutionflowbetweenagoroutineandtheschedulerisfast

Fastcontextswitching

Process/Thread 3000to4500nsCPUAffinity 1300to1900nsCPUAffinity

Goroutine:<10ns

Goroutines:howdoesitdoitFastcontextswitching

Goroutines:howdoesitdoit

TLSisusedtojumpfromaGoroutinetothescheduler

ClassicTLScanbecostlydependingontheplatform

ThreadLocalStorage

Goroutines:howdoesitdoit

GotakesadvantageofaunusedMMUregistryifpossible

ThreadLocalStorage

Netpoller:howdoesitdoit

Netpoller:howdoesitdoit

TheschedulerunparksGoroutinesjustwhenI/Oisavailable.

Hiddeninthescheduler

Netpoller:howdoesitdoit

epollforLinux

kqueueforMacOS

I/OCompletionportsforWindows

SyscallsdependingontheOS

Channels:howdoesitdoit

Channels:howdoesitdoit

Lock-freeforawriterinanon-fullchannel.

Lock-freeforareaderinanon-emptychannel.

Criticalsectionstaysshortforblockingcalls.

Limitedusageofmutexes

Channels:howdoesitdoit

Lock-freeoperationsuseatomicCopyAndSwapformodernprocessors

Atomics

Channels:howdoesitdoit

Gomutexesareimplementedwithfutexes(FastUserspacemuTEX).

Fastmutexes

duckie.github.io/boson

SeethosethingsimplementedinC++

Thankyouverymuch