Skip to content

Commit

Permalink
stringmap: optimize memory layout (#12)
Browse files Browse the repository at this point in the history
name                                           old alloc/op   new alloc/op   delta
Int64/Store/skipmap-16                            96.0B ± 0%     96.0B ± 0%     ~     (all equal)
Int64/Load50Hits/skipmap-16                       0.00B          0.00B          ~     (all equal)
Int64/30Store70Load/skipmap-16                    28.3B ± 2%     28.3B ± 2%     ~     (p=1.000 n=20+20)
Int64/1Delete9Store90Load/skipmap-16              8.00B ± 0%     8.00B ± 0%     ~     (all equal)
Int64/1Range9Delete90Store900Load/skipmap-16      8.00B ± 0%     8.00B ± 0%     ~     (all equal)
String/Store/skipmap-16                            128B ± 0%      112B ± 0%  -12.50%  (p=0.000 n=20+20)
String/Load50Hits/skipmap-16                      15.0B ± 0%     15.0B ± 0%     ~     (all equal)
String/30Store70Load/skipmap-16                   49.0B ± 0%     44.0B ± 0%  -10.20%  (p=0.000 n=19+20)
String/1Delete9Store90Load/skipmap-16             25.0B ± 0%     24.0B ± 0%   -4.00%  (p=0.000 n=17+20)
String/1Range9Delete90Store900Load/skipmap-16     25.0B ± 0%     24.0B ± 0%   -4.00%  (p=0.000 n=16+20)
  • Loading branch information
zhangyunhao116 authored Aug 30, 2024
1 parent 4853390 commit 81e3d4f
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 57 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
go-version: [1.18, 1.19, 1.20]
go: ['1.18', '1.19', '1.20', '1.21', '1.22', '1.23']
os: [ubuntu-latest, macos-latest, windows-latest]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
cache: false

- name: CI
run: |
go version && go test ./... -race
6 changes: 3 additions & 3 deletions gen_func.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gen_int.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gen_int32.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gen_int32desc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gen_int64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gen_int64desc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gen_intdesc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gen_ordered.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gen_ordereddesc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gen_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gen_stringdesc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gen_uint.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gen_uint32.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gen_uint32desc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gen_uint64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gen_uint64desc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gen_uintdesc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions skipmap.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ type {{.StructPrefix}}Map{{.StructSuffix}}{{.TypeParam}} struct {
}

type {{.StructPrefixLow}}node{{.StructSuffix}}{{.TypeParam}} struct {
key {{.KeyType}}
value unsafe.Pointer // *any
flags bitflag
key {{.KeyType}}
next optionalArray // [level]*{{.StructPrefixLow}}node{{.StructSuffix}}
mu sync.Mutex
level uint32
mu sync.Mutex
next optionalArray // [level]*{{.StructPrefixLow}}node{{.StructSuffix}}
}

func new{{.StructPrefix}}Node{{.StructSuffix}}{{.TypeParam}}(key {{.KeyType}}, value {{.ValueType}}, level int) *{{.StructPrefixLow}}node{{.StructSuffix}}{{.TypeArgument}} {
Expand Down

0 comments on commit 81e3d4f

Please sign in to comment.