# InternPool: improve hashing performance · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/82f6f164a1af6557451e580dcf3197ad94e5437e)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 82f6f164a1af6557451e580dcf3197ad94e5437e

Requested commit: 82f6f164a1af6557451e580dcf3197ad94e5437e

Commit: 82f6f164a1af6557451e580dcf3197ad94e5437e

Tree: 6a88050cac9da741c2ae8434ef0fe2989c411ee5

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
InternPool: improve hashing performance

Key.PtrType is now an extern struct so that hashing it can be done by
reinterpreting bytes directly. It also uses the same representation for
type_pointer Tag encoding and the Key. Accessing pointer attributes now
requires packed struct access, however, many operations are now a copy
of a u32 rather than several independent fields.

This function moves the top two most used Key variants - pointer types
and pointer values - to use a single-shot hash function that branches
for small keys instead of calling memcpy.

As a result, perf against merge-base went from 1.17x ± 0.04 slower to
1.12x ± 0.04 slower. After the pointer value hashing was changed, total
CPU instructions spent in memcpy went from 4.40% to 4.08%, and after
additionally improving pointer type hashing, it further decreased to
3.72%.

```

## Parents

- [c7d65fa3685a5f48cfedaa7a1adf758e1dc6d219](https://git.cafe/gitcafe/zig/commit/c7d65fa3685a5f48cfedaa7a1adf758e1dc6d219?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/82f6f164a1af6557451e580dcf3197ad94e5437e?format=markdown)
