Why is GO much faster than CPython?

how much faster can go be than CPython

in this benchmark python takes 100x longer than GO due to GO's multithreading

because in GO you can run multiple threads at once and they are scheduled faster than python

what are threads?

unit of context

like when u call a program line by line, that's a thread

run two diff parts of program at same time, that's 2 threads

python can only use one thread of a time due to global interpreter lock

this is because underneath python uses oldschool C functions

and those C functions aren't threadsafe

if you call a non-threadsafe function concurrently from 2 different threads you may get different results

so python only lets you execute one thread at a time even if you have multiprocessor machine

python didn't remove this because its hard and would break a lot of libraries depending on GIL

go can run multiple threads at once with no global-interpret lock

if your machine has multiple processors it can be truly parallel

go schedules work smarter than CPython

if a go thread gets blocked it doesn't just wait, it swaps it out with some other work that can be done so all the work gets finished faster