Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/compile: wasted bucket allocated on stack for non-escaping map when hint is not small #20184
When there's a non-escaping map, we allocate a bucket for it on the stack. See walk.go, func walkexpr, case OMAKEMAP. But if there's a size hint big enough that we want to preallocate some buckets non-lazily, we ignore the bucket parameter passed to makemap. See hashmap.go, func makemap, handling of buckets param. We should not allocate a bucket on the stack if we're just going to ignore it in makemap.
This requires cmd/compile knowing whether the runtime will decide it needs to preallocate some buckets. There's already a lot of shared (duplicated) knowledge between the compiler and runtime, so this isn't the end of the world.
Low priority, since this case is probably rare. But this might make a good starter project for someone interested in the compiler.