The Perfect Follow-Up to Dictionary Performance - mapKeyedValues (SE-0510)

Before WWDC26, I published an article called “Advanced Dictionaries: Performance and Hidden Traps.” In that article, I explained why mapValues(_:) is very fast because it reuses the same hash structure and memory slots. However, we had a big problem: mapValues does not give us the keys inside the closure. To use keys, we had to choose slow methods like reduce(into:) which cause a lot of rehashing.

At WWDC26, Apple solved this problem with Dictionary.mapKeyedValues (SE-0510).

I wrote a new follow-up article that connects my previous dictionary performance notes with this new API. In this short post, I talk about:

  • A quick recap of older performance traps like uniqueKeysWithValues.
  • How mapKeyedValues lets us use keys as context with less performance tax.

You can read the article here

I would love to hear your thoughts on this new API and my article

1 Like