Get the latest tech news

Requiem for a Hash Function, or: How I learned to love package maphash


I am coming off from surgery right now and have some time on my hands, so I wanted to share a story about a learning experience. This post is a bit of a dual purpose one on a teachable moment as a software engineer — a chance to offer a retrospective from bad decisions and earn penance therefor. There is one episode that sticks out in my memory with a fair bit of shame: implementing the original metric hashing for the metric family data type in Prometheus’s client metrics. This hashing was used in the internals of the client metrics, so users wouldn’t be exposed to it directly — except in terms of CPU cost!

Important: maphash.WriteComparable internally performs TLV-like delimiting on the data hashing, meaning capturing information on string length, item count, and similar are not needed when you directly use this API. Now, I can imagine some readers taking umbrage that I’ve saved a crucial point for the end: in the vast majority of situations, creating a manual hashing mechanism is unnecessary. I haven’t dug into its guts too deeply, but it appears to recursively generate instructions that get added to an intermediate representation(IR) store that are returned eventually as a closure.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of requiem

requiem

Photo of package maphash

package maphash

Photo of Hash Function

Hash Function

Related news:

News photo

Requiem for an Exit

News photo

Resident Evil 9: Requiem's director explains how in one crucial way, it is the "most extreme" title in the series yet

News photo

Video games calm the body after stress, even when players feel on edge - physiological stress indicators decreased while participants were playing the video game A Plague Tale: Requiem, regardless of which part of the game they were playing.