Skip to content

internal/sync: Add support for wide trie in sync.HashTrieMap and bugfix - #160

Open
lxq015 wants to merge 1 commit into
go1.26.5-zte-devfrom
euler_HashTrieMap
Open

lxq015 wants to merge 1 commit into
go1.26.5-zte-devfrom
euler_HashTrieMap

Conversation

@lxq015

@lxq015 lxq015 commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

https://gitcode.com/openeuler/golang/pull/51

This CL adds a "wide trie" implementation of internal/sync.HashTrieMap (the
map backing sync.Map), which raises the branching factor of internal nodes
from 16 (4 bits per level) to 128 (7 bits per level). This reduces the maximum
tree depth from 16 to ~10 levels, cutting the number of dependent atomic loads
and pointer dereferences on every lookup/update path. It also fixes an edge
case when expanding entries whose hashes collide down to the final hash level,
covered by new regression tests.

Usage: build with GOEXPERIMENT=widetrie

goos: linux
goarch: riscv64
pkg: internal/sync
cpu: Spacemit(R) X60
│ before.txt │ after.txt │
│ sec/op │ sec/op vs base │
HashTrieMapLoadSmall 87.70n ± 6% 81.36n ± 4% -7.23% (p=0.002 n=6)
HashTrieMapLoad 109.7n ± 1% 109.7n ± 1% ~ (p=1.000 n=6)
HashTrieMapLoadLarge 1610.0n ± 1% 966.6n ± 1% -39.96% (p=0.002 n=6)
HashTrieMapLoadOrStore 111.6n ± 1% 114.4n ± 2% +2.51% (p=0.009 n=6)
HashTrieMapLoadOrStoreLarge 1.969µ ± 18% 1.731µ ± 10% ~ (p=0.065 n=6)
geomean 320.9n 279.5n -12.88%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant