TLDR Web Dev · ARTICLES & TUTORIALS
WHAT'S //GO:NOSPLIT FOR?
Summary from the TLDR Web Dev newsletter
Go's `//go:nosplit` directive removes the usual stack overflow check from functions to improve performance. Nosplit functions skip the preemption check that normally compares the stack pointer against a limit and calls `runtime.morestack` when needed, making them about 2% faster in hot loops but potentially much faster when the goroutine struct isn't cached. However, nosplit functions are dangerous because they can cause stack overflows, so the Go linker includes safety checks to make sure chains of nosplit functions don't exceed a small stack limit (792 bytes).