<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/a-million-go-map-entries-take-38mb-not-16mb-lnqjibqce" -->

---
title: A Million Go Map Entries Take 38MB, Not 16MB | daily.dev
description: A deep investigation into why Go's map[int64]int64 costs roughly 37.8 bytes per entry instead of the expected 16 bytes on Go 1.27.1. The piece traces the cause...
canonical: https://daily.dev/posts/a-million-go-map-entries-take-38mb-not-16mb-lnqjibqce
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: A Million Go Map Entries Take 38MB, Not 16MB | daily.dev
og:description: A deep investigation into why Go's map[int64]int64 costs roughly 37.8 bytes per entry instead of the expected 16 bytes on Go 1.27.1. The piece traces the cause...
og:url: https://daily.dev/posts/a-million-go-map-entries-take-38mb-not-16mb-lnqjibqce
og:image: https://api.daily.dev/og/posts/LnQjIBqce.png
og:image:alt: A Million Go Map Entries Take 38MB, Not 16MB
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# A Million Go Map Entries Take 38MB, Not 16MB

**[Awesome Go](https://daily.dev/sources/awego)** · 20 min read · 30 upvotes · 1 comments

## Summary

A deep investigation into why Go's map[int64]int64 costs roughly 37.8 bytes per entry instead of the expected 16 bytes on Go 1.27.1. The piece traces the cause to the Swiss Tables map implementation that replaced the bucket-based map in Go 1.24: groups of 8 slots that are 50-56% empty by design, padding for zero-size values in sets (struct{} and bool now cost identically), 128-byte inline value limits, and the fact that deletes and clear() never shrink or return memory to the OS. Includes benchmarks comparing grown vs. preallocated maps, an in-progress GOEXPERIMENT=mapsplitgroup fix landing in Go 1.28, and practical advice (prefer bitsets/slices for dense integer sets, preallocate when size is known, rebuild maps after large deletes).

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://dev.to/nazar-boyko/a-million-go-map-entries-take-38mb-not-16mb-2ij3>

## Questions this post answers

### Why does a Go map[int64]int64 with a million entries use 37.8MB instead of the expected 16MB?

The extra memory comes mostly from empty slots by design, not from a per-entry header. Go's Swiss Tables map (default since Go 1.24) allocates slots in groups of 8, and tables grow by doubling when 7/8 full, so right after a doubling more than half the slots sit empty. A million-entry map lands just past a split at 917,504 entries, producing 37.8 bytes per entry instead of 16.

_Developers tuning memory-heavy Go services can track runtime memory-layout changes like this through daily.dev._

### Does map[string]struct{} still use less memory than map[string]bool in Go 1.24 and later?

No, on Go 1.24 through 1.27 both cost exactly the same amount of memory. The compiler pads any non-empty struct ending in a zero-size field by one byte, then rounds that up to eight bytes for alignment, which matches the eight bytes a bool slot also gets rounded to. This was confirmed in Go issue 71368, where a maintainer stated both now allocate identically.

_Anyone choosing set representations in Go can check runtime memory quirks like this before optimizing._

### Does deleting all keys or calling clear() on a Go map free its underlying memory?

No, deleting every key or calling clear(m) on a Go map does not return any memory to the heap. The runtime's Clear function only marks slots empty and leaves a TODO comment about shrinking the directory; nothing hands a table back while the map is alive. The only way to reclaim memory is copying surviving entries into a freshly made map and dropping the old one.

_Teams debugging memory growth in long-running Go services can verify map-shrinking behavior like this on daily.dev._

## Community discussion

Top comments from developers on daily.dev.

**@calindinis** · 3 upvotes

> Turning go into java I see.

## Similar posts on daily.dev

- [Hash tables in Go and advantage of self-hosted compilers](https://daily.dev/posts/hash-tables-in-go-and-advantage-of-self-hosted-compilers-tkdlr8n5e) · Lobsters · 4 upvotes · 0 comments
- [Slices, Maps, and Channels](https://daily.dev/posts/slices-maps-and-channels-etwxxtg4k) · Planet Golang · 27 upvotes · 1 comments
- [Internals for Interns](https://daily.dev/posts/internals-for-interns-fg0xibngw) · Hacker News · 0 upvotes · 0 comments

---

Tags: [#performance](https://daily.dev/tags/performance), [#golang](https://daily.dev/tags/golang)

[View this post on daily.dev](https://daily.dev/posts/a-million-go-map-entries-take-38mb-not-16mb-lnqjibqce)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"A Million Go Map Entries Take 38MB, Not 16MB","url":"https://daily.dev/posts/a-million-go-map-entries-take-38mb-not-16mb-lnqjibqce","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/a-million-go-map-entries-take-38mb-not-16mb-lnqjibqce"},"datePublished":"2026-09-17T20:29:30.216Z","dateModified":"2026-09-17T22:55:13.034Z","description":"A deep investigation into why Go's map[int64]int64 costs roughly 37.8 bytes per entry instead of the expected 16 bytes on Go 1.27.1. The piece traces the cause...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/9641156aef337822eac4e5c64837e800?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/9641156aef337822eac4e5c64837e800?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Awesome Go","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Awesome Go","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/awego","url":"https://daily.dev/sources/awego"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/a-million-go-map-entries-take-38mb-not-16mb-lnqjibqce","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":30},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"performance,golang","timeRequired":"PT20M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Awesome Go","item":"https://daily.dev/sources/awego"},{"@type":"ListItem","position":3,"name":"A Million Go Map Entries Take 38MB, Not 16MB"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/a-million-go-map-entries-take-38mb-not-16mb-lnqjibqce","comment":[{"@type":"Comment","text":"Turning go into java I see.","datePublished":"2026-09-18T12:27:52.239Z","url":"https://daily.dev/posts/LnQjIBqce#c-Use25jQ1u","author":{"@type":"Person","name":"Calin Dinis","url":"https://daily.dev/calindinis","image":"https://lh3.googleusercontent.com/a/ACg8ocIivX4QCjrIZwuMY7skYlJAYJ1qH_yA2IQ3XcT9DQb4vQPM4w=s96-c"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/a-million-go-map-entries-take-38mb-not-16mb-lnqjibqce#faq","mainEntity":[{"@type":"Question","name":"Why does a Go map[int64]int64 with a million entries use 37.8MB instead of the expected 16MB?","acceptedAnswer":{"@type":"Answer","text":"The extra memory comes mostly from empty slots by design, not from a per-entry header. Go's Swiss Tables map (default since Go 1.24) allocates slots in groups of 8, and tables grow by doubling when 7/8 full, so right after a doubling more than half the slots sit empty. A million-entry map lands just past a split at 917,504 entries, producing 37.8 bytes per entry instead of 16. Developers tuning memory-heavy Go services can track runtime memory-layout changes like this through daily.dev."}},{"@type":"Question","name":"Does map[string]struct{} still use less memory than map[string]bool in Go 1.24 and later?","acceptedAnswer":{"@type":"Answer","text":"No, on Go 1.24 through 1.27 both cost exactly the same amount of memory. The compiler pads any non-empty struct ending in a zero-size field by one byte, then rounds that up to eight bytes for alignment, which matches the eight bytes a bool slot also gets rounded to. This was confirmed in Go issue 71368, where a maintainer stated both now allocate identically. Anyone choosing set representations in Go can check runtime memory quirks like this before optimizing."}},{"@type":"Question","name":"Does deleting all keys or calling clear() on a Go map free its underlying memory?","acceptedAnswer":{"@type":"Answer","text":"No, deleting every key or calling clear(m) on a Go map does not return any memory to the heap. The runtime's Clear function only marks slots empty and leaves a TODO comment about shrinking the directory; nothing hands a table back while the map is alive. The only way to reclaim memory is copying surviving entries into a freshly made map and dropping the old one. Teams debugging memory growth in long-running Go services can verify map-shrinking behavior like this on daily.dev."}}]}
```

