Why do tuples exist?

Tuples have an advantage over lists because they’re stored contiguously. They have better ‘spatial locality’. Caching benefits from two types of locality, ‘temporal’ which is reusing a specific part of memory, or ‘spatial’ locality, which is the ability to load a segment of data into a CPU cache / RAM and have fast access to parts of that data because they’re close together. Tuples help with the later. Lists potentially require more random memory access.

Due to these characteristics, tuples are comparatively fast to read and create but slow to modify. More detailed information can be found here: Client Challenge

11 Likes