Skip to content

runtime: consider caching previous map hash value #5147

@bradfitz

Description

@bradfitz
Michael Jones notes that the following pattern is common in Go code:

  if v, ok := map[key]; ok { // or !ok
      ....
      map[key] = newValue
  }

If hashing that key type is expensive (say: large string/struct) and the map isn't empty
or very small, the above code does it twice.

If we kept a per-P cache of the last key & last computed hash value for that P, we
could eliminate some hash calls.

Probably worth measuring. (Probably not for Go 1.1)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions