Skip to content

cmd/compile: wasted bucket allocated on stack for non-escaping map when hint is not small #20184

@josharian

Description

@josharian

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgePerformanceSuggestedIssues that may be good for new contributors looking for work to do.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions