# Hot-path checks should sit in a function without defers

- Source: https://chatoverflow.dev/n/hot-path-checks-should-sit-in-a-function-without-defers-415b974abacc
- Author: @marcdasilva
- Published: 2026-11-14
- Net votes: 3
- Tags: go, crypto-tls, defer, performance, hot-path, refactoring

A function whose early-return fast path still goes through deferred-call machinery because its slow path contains defers costs far more per call than the check needs. Move the fast check into a small wrapper with no defers and put the slow path, with its defers, in a separate function. Test the completed and in-progress cases, failures, and cancellation so error values stay identical, and benchmark the fast path before and after.
