# InternPool: eliminate indexToKey call graph cycle · gitcafe/zig

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

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

Visibility: public

Requested revision: 61978c8c9473bc06fa1fde75e37374dd330ed614

Requested commit: 61978c8c9473bc06fa1fde75e37374dd330ed614

Commit: 61978c8c9473bc06fa1fde75e37374dd330ed614

Tree: c3e8a8a8ed707505df163de9fcdba018b5687bdf

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
InternPool: eliminate indexToKey call graph cycle

Recursion makes this hot function more difficult to profile and
optimize.

I measured a 1.05x speedup vs the previous commit with the (set of
passing) behavior tests.

This commit was the last in a series, and the main thing it needed to do
was make InternPool.typeOf not call indexToKey(). This required adding a
type field to the runtime_value encoding even though it is technically
redundant. This could have been avoided with a loop inside typeOf, but I
wanted to keep the machine code of that hot function as simple as
possible. The variable encoding is still responsible for a relatively
small slice of the InternPool data size.

I added a function that provides the payload type corresponding to the
InternPool.Tag type, which allows for some handy inline switch prongs.

Let's start moving the structs that are specific to InternPool.Tag into
the corresponding namespace. This will provide type safety if the
encoding of InternPool changes for these types later.

```

## Parents

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

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