Go 1.24版本用基于Swiss Tables设计的新实现替换了内置map的运行时架构1。这一改进通过优化数据结构和查询算法,使map操作性能最高提升60%1。
新设计将map组织为由多个group组成的table结构,每个group最多存储8个键值对1。系统采用64位control word来描述每个slot的状态1,并利用两个哈希值H1和H2分别用于计算起始group和过滤group内的slots1。当单个group满载后,map扩展为包含多个group的table1。单个table最多包含128个groups(1024个slots),超出此上限时会分裂成两个新table1。为了管理多个table,系统采用目录结构,通过globalDepth和localDepth分别表示全局和局部深度1。
为了实现高效的组查找,Go使用三角形探测序列进行步长递增搜索1。加载因子的上限设定为7/8(87.5%),保留部分空slots来提高查找效率1。Go 1.27进一步引入了实验性特性mapsplitgroup,通过分离keys和values数组来减少内存占用并改善缓存局部性1。完整应用基准测试显示,与旧实现相比,平均CPU时间改善约1.5%1。
Go 1.24 replaced its map runtime implementation with a design based on Swiss Tables, introducing significant architectural changes to how the language handles this fundamental data structure.1 Each group within the map stores up to eight key-value pairs and uses a 64-bit control word to describe the state of every slot.1 The implementation employs two hash components: H1 determines the starting group location, while H2 filters within the eight slots of a given group.1
The map's growth strategy scales from a single group to multiple groups organized into a table structure when capacity is exceeded.1 A table can accommodate up to 128 groups containing 1,024 slots total; when this limit is reached, the table splits into two new tables.1 The system manages multiple tables through a directory structure that tracks both global depth and local depth parameters.1 Group lookup follows a triangular probe sequence with step lengths of +1, +2, +3 and so on.1 To maintain search efficiency while preserving available slots, the load factor is capped at 7/8, or 87.5%.1
Performance improvements are substantial under the new design, with map operations showing gains up to 60 percent compared to the previous implementation, while complete application benchmarks demonstrate an average CPU time improvement of approximately 1.5 percent.1 An experimental feature coming in Go 1.27 called mapsplitgroup separates keys and values into distinct arrays, reducing memory consumption and enhancing cache locality.1
评论
还没有评论,欢迎留下第一条。