0 day streak
Code library

Expert Go exercises

Read these Expert Go snippets line by line — each one comes with a written breakdown of what the code does and why.

Go · Expert

Reducing GC Pressure with sync.Pool

sync.Pool allows for object reuse, significantly reducing the frequency of garbage collection cycles in high-throughput applications by recycling allocated memory.

PerformanceDesign PatternsAsync & Concurrency
Open snippet →
Go · Expert

Generic Type Set Constraints

Type sets in interfaces allow generics to restrict types to a specific union. The tilde (~) operator includes types that share the same underlying primitive type.

SyntaxData TypesFunctions
Open snippet →
Go · Expert

Request Collapsing with singleflight

The singleflight package provides a duplicate function call suppression mechanism. It ensures that for a given key, only one execution of a function is in flight at a time. If multiple goroutines c…

PerformanceDesign Patterns
Open snippet →
Go · Expert

High-Concurrency Map with Lock Striping

Lock striping is a pattern to reduce contention on a shared resource by splitting it into multiple independent 'shards', each with its own lock. In a highly concurrent environment, a single global…

PerformanceDesign Patterns
Open snippet →
Go · Expert

Resource Throttling with Weighted Semaphores

Weighted semaphores allow you to control access to a shared resource pool where different tasks may consume different amounts of that resource. Unlike a simple channel-based semaphore which only co…

Async & ConcurrencyDesign Patterns
Open snippet →