Use //go:noescape to optimize pointer handling and //go:nosplit to prevent stack growth interruptions in critical Go functions.
Use //go:noescape to tell the compiler a pointer argument does not escape the function, and //go:nosplit to mark a function as safe from stack splitting during execution.
//go:noescape
func runtime_arena_arena_Slice(arena unsafe.Pointer, slice any, cap int)
//go:nosplit
func criticalSection() {
// Code that must not be interrupted by stack growth
}
These directives are hints to the Go compiler for optimizing performance and safety. //go:noescape tells the compiler that a pointer stays local, allowing it to skip garbage collection checks. //go:nosplit ensures a function runs without interruption, which is critical for low-level code that cannot handle a stack resize mid-execution.