Skip to content

runtime: randomize iteration order of small maps #6719

Closed
@ianlancetaylor

Description

@ianlancetaylor
The Go spec says that when using range over a map, the iteration order is not specified.
 With our current implementation, the iteration order is always consistent for maps with
8 or fewer elements.  This is not wrong, but it means that when people write tests that
use small maps, they sometimes do not notice that they are depending on a consistent
iteration order.  That dependency fails when they run the tests with gccgo, which uses a
different map implementation.

My suggestion is that we change the map code so that when iterating over a bucket it
randomly goes either up or down.  That will cause a different iteration order even for
small maps, and thus make tests more reliable, with no real expense in runtime.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions