It's worth noting that the "self-hosted compiler" thing here is a red herring.<p>E.g. the JVM is a C++ project, but you can easily read the HashMap implementation, because it's part of the standard library, not part of the runtime.
Interesting how the Go team is the utmost example of thinking through and bikeshedding ad infinitum even the tiniest angles of each proposal (something that I like a lot by the way), which is part of the reason that popular feature requests take years to come, and others such as the `Set` type are binned because of not providing enough added value.<p>But an implementation change that will for sure baloon the memory usage of everybody's code making heavy use of Hashmap-as-set (a popular idiom)? Yeah no problem, change shipped.
The Go team has a lot of old school nerd cred thats why it gets away with a lot of stupid shit. Then a fan base of nerd hero worshippers beat down any discussion about doing things a better way with: SIMPLICITY.<p>Its frustrating and I say this as someone who has been writing Go for around a decade.
There’s a big difference between a change which modifies the languages API, and one that just modifies the implementation of the API.<p>Given GoLangs compatibility guarantee, any mistake in the design of a language API has to be preserved forever, and is very difficult to improve.<p>But implementations of the GoLang spec and language APIs are much easier to evolve. There’s nothing preventing the Go team rolling out future improvements to deal with this issue, without having to worry about long term consequences. There’s also nothing preventing other implementations of the GoLang spec choosing a different approach.
I think all language definitions have lots of implicit non-functional requirements.<p>When the main implementation of a language changes one of them, that technically isn’t a breaking change, but it still is one, as existing programs mays have to be changed in order to keep satisfying their own non-functional requirements.
It's called marketing. If Go quietly made something perfect, nobody would know of its existence. Do stupid things that gets people talking and everyone soon learns about you.
Issue tracking this <i>“regression”</i>:
<a href="https://github.com/golang/go/issues/71368" rel="nofollow">https://github.com/golang/go/issues/71368</a>
> Using empty structs also hurts readability<p>An empty struct is idiomatic and expected to be used in a Set type. When/if the memory optimization is reintroduced, no code change will be needed to take advantage of it.
Using a bool instead of empty struct also means that there is more way to use it wrong: check the bool instead of if the key exist, set the bool incorrectly, etc...<p>I would argue using bool hurts readability more.<p>Even better write/use a simple library that calls things that are sets `Set`.
I could've sworn we got "sets" in the Go's standard library along with the "maps" module but... apparently not? Huh.
Almost made it into 1.18 but looks like it doesn't add enough value and has some open questions like what to use for a backing data type and what complexity promises to make.<p><a href="https://github.com/golang/go/discussions/47331" rel="nofollow">https://github.com/golang/go/discussions/47331</a>
Honestly insane in 2025 to not have a generic Set.
e.g. <a href="https://pkg.go.dev/github.com/zyedidia/generic/mapset" rel="nofollow">https://pkg.go.dev/github.com/zyedidia/generic/mapset</a>
I also feel like map[T]struct{} communicates its purpose way better than map[T]bool. When I see a bool I expect it to represent a bit of information, I don't see why using it as a placeholder for "nothing" would be more readable than a type that can literally store nothing.
Isn't it empty interface that's idiomatic? Or was anyway?<p>edit: I may be wrong here
I wonder if the compiler really needs to allocate 1 byte so you can get the address of the struct {}<p>In the general case then yes, but here you can't take addresses of dictionary values (the compiler won't let you) so adding 1 byte to make a unique pointer for the struct {} shouldn't be necessary.<p>Unless it is used in the implementation of the map I suppose.<p>So I conjecture a bit of internal magic could fix this.
> Another takeaway here, as always, is not to trust everything LLMs say.<p>I would go even farther and say to not trust anything they say. Always be skeptical, always verify.
Rust HashSets are HashMaps with an empty type as the value type, but the compiler actually optimizes away the storage for the keys based on the type being empty. Go doesn't bother to either define a set type like most languages do, or to optimize the map implementation with an empty type as the value type
Empty struct is good for representing non-nil zero-length information, for example this is ideal for many use cases where channels are involved. Or of you have a http route and you want to return empty response(200 OK or 204 No Content, instead of error).<p>Boolean on the other hand inherently contains two information: either true or false. ie. there will always be information and it will always be one of two values.<p>This is similar to *struct{} where we can signal no information, or false, by returning/passing nil or initiated pointer to empty struct as true/value present.<p>For maps, bool makes more sense as otherwise we just want a list with fast access to determine whether value in the list exists or not. Which is often something we might want. But it should not detract form the fact that each type has its own place and just because new implementation for maps ignores this, in this particular use, case does not make them worse than previous version.<p>tl;dr it is good to know this fact about the new swiss maps, but it should not have any impact on programming an design decisions whatsoever.
So what is this article about?<p>1. How to do sets in Go?<p>2. What changed between Go 1.24 and 1.25?<p>3. Trusting an LLM?<p>4. Self-hosted compilers?<p>It is not clear at all. Also there are no conclusions, it's purely a waste of time, basically the story of a guy figuring out for no reason that the way maps are implemented has changed in Go.<p>And the title is about self-hosted compilers, whose "advantage" turned out to be just that the guy was able to read the code? How is that an advantage? I guess it is an advantage for him.<p>The TypeScript compiler is also written in Go instead of in TypeScript. So this shouldn't be an advantage? But this guy likes to read Go, so it would also be an advantage to him.
I agree that the article is a bit unfocused about the supporting material. But the primary topic is clear: it's about the memory consumption of the Go map implementation.<p>This is an article written by a real human person, who's going to meander a bit. I prefer that over an LLM article which is 100% focused, 100% confident, and 100% wrong. Let's give the human person a little bit of slack.
I think it is quite obvious - the author has found out that a memory trick that used to work in previous Go versions no longer works - in this sigular use case.