Use //go:noinline and //go:nosplit directives before a function to control compiler inlining and stack growth behavior.
Use //go:noinline to prevent the compiler from inlining a function and //go:nosplit to prevent the stack from growing during execution. Place these directives on their own line immediately before the function declaration.
//go:noinline
func NoInlineFunc() {
// Function body
}
//go:nosplit
func NoSplitFunc() {
// Function body
}
These are instructions you give to the Go compiler to control how it handles specific functions. //go:noinline tells the compiler to keep a function separate instead of copying its code into other places, which helps with debugging or size limits. //go:nosplit tells the compiler not to move the function's data to a larger memory area while it runs, which is critical when working with low-level system code.