Performance
- Common Go Footguns: Appending to slices #2
Jan 18, 2026
-
5 min read
This post is a followup to Common Go Footguns: Appending to slices, where I demonstrated that appending to a slice can be a surprising source of impactful performance problems. While this post focuses on Go specifics, much of the methodology and thought process involved in this post applies to most performance related work.
We know that pre-allocating our slices is good. But, what if you don’t know how many items you need to append to your slice? What if you’re appending during an expensive
O(n³)algorithm? Most engineers I’ve worked with would really resist doingO(n³)work just to know the size of a slice to pre-allocate. It seems quite wasteful. In the past I’ve conceded here. - Common Go Footguns: Appending to slices
Aug 25, 2024
-
3 min readThis is the second post in a series on common Go footguns. This post demonstrates the performance impacts of appending a known number of elements to a slice without doing any pre-allocation. This is one of the most common and easily fixed performance issues I see in pull requests on a regular basis.