Skip to content

hash/maphash: purego implementation is not updated #69940

@ErikPelli

Description

@ErikPelli

According to lines 33 & 34 of hash/maphash/maphash_purego.go:

// This is a port of wyhash implementation in runtime/hash64.go,
// without using unsafe for purego.

However, when I look to the effective code inside this file, the implementation looks very different from the one in runtime/hash64.go, and I think it should be changed to match it accordingly.

Among the differences:

  1. In the runtime/hash64.go, the variable hashkey is used often, but it's totally absent from the maphash_purego.go implementation. This is a [4]uint64 array that contains random values, generated during the package initialization inside runtime/alg.go. I think an init() function should be added to the maphash_purego.go file to generate random uint64 in a private global variable, similar to the hashkey one.
  2. On April 2024 (6 months ago), hash64.go implementation has been updated, in commits ef2f339 and 35c6193, now the global hashkey variable is used even more (should we add an equivalent in maphash too? Related to point 1) and 4 out of 5 constants have been removed, these changes are currently missing from the hashmap_purego.go implementation.
  3. Although the comments says the the code afterward is just a porting from hash64.go, the code structure looks very different. For example: the default case of the hash64 implementation, in this implementation is written before the whole switch, and a lot of cases are grouped under a new default case. Maybe these differences are correct, but there is no documentation to explain them, and I don't understand why they are not directly part of runtime/hash64.go too if the code does the same thing? Maybe they are less performant? Someone has any hint about this one?

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions