Closed Bug 1832329 Opened 2 years ago Closed 2 years ago

Simplify hashing of unique IDs to improve performance

Categories

(Core :: JavaScript Engine, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
115 Branch
Tracking Status
firefox115 --- fixed

People

(Reporter: jonco, Assigned: jonco)

References

(Blocks 1 open bug)

Details

(Whiteboard: [sp3])

Attachments

(1 file)

Currently we pass unique IDs through mozilla::HashGeneric() to generate a hash code which we pass to the hash table, which then processes it further with ScrambleHashCode().

The latter step is sufficient to generate good hash codes. The documentation comment states:

 * This function aims to produce as uniform an output distribution as possible,
 * especially in the most significant (leftmost) bits, even though the input
 * distribution may be highly nonrandom, given the constraints that this must
 * be deterministic and quick to compute.

So we should be able to return the ID directly as the hash code. Also, since these are assigned sequentially we can the top 32 bits as collissions in the bottom 32 bits are highly unlikely.

If further justification were needed I discovered that DefaultHasher<uint64_t>::hash works like this already:

    // Just convert the integer to a HashNumber and use that as is. (This
    // discards the high 32-bits of 64-bit integers!) ScrambleHashCode() is
    // subsequently called on the value to improve the distribution.
Whiteboard: [sp3]

This removes the first HashGeneric step and relies on the ScrambleHashCode step
that happens in the hash table implementation.

This improved the benchmark result from 47.5 ns to 44.1 ns, a reduction of
7.2%.

Assignee: nobody → jcoppeard
Status: NEW → ASSIGNED
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 115 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: