ortuman / nuke

⚡ A memory arena implementation for Go.
Apache License 2.0
500 stars 13 forks source link

nuke/monotoniic: reset's behavior and a little bit of improvements #19

Open AnyCPU opened 8 months ago

AnyCPU commented 8 months ago

@ortuman Hi!

there is a little bit of improvements for current version of the nuke:

the most important changes is related to behavior of the reset method. I guess the reset method should always reset memory and release it optionally.

in general I would like to see two separate methods like (suggestion):

as an idea in the air, we could have only one method Free() (like on Go's Arena) that under the hood always resets and releases memory.

Benchmark results for the nuke latest version:

go test -bench=. ./...
goos: darwin
goarch: amd64
pkg: github.com/ortuman/nuke
cpu: Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
BenchmarkRuntimeNewObject/100-8                   914125              1297 ns/op             800 B/op        100 allocs/op
BenchmarkRuntimeNewObject/1000-8                   87066             13075 ns/op            8000 B/op       1000 allocs/op
BenchmarkRuntimeNewObject/10000-8                   8016            130695 ns/op           80000 B/op      10000 allocs/op
BenchmarkRuntimeNewObject/100000-8                   878           1288538 ns/op          800009 B/op     100000 allocs/op
BenchmarkMonotonicArenaNewObject/100-8             33520             35639 ns/op               0 B/op          0 allocs/op
BenchmarkMonotonicArenaNewObject/1000-8            24528             49212 ns/op               0 B/op          0 allocs/op
BenchmarkMonotonicArenaNewObject/10000-8            6745            163495 ns/op               0 B/op          0 allocs/op
BenchmarkMonotonicArenaNewObject/100000-8            846           1353877 ns/op               0 B/op          0 allocs/op
BenchmarkConcurrentMonotonicArenaNewObject/100-8                   32326             36768 ns/op               0 B/op          0 allocs/op
BenchmarkConcurrentMonotonicArenaNewObject/1000-8                  21222             53665 ns/op               0 B/op          0 allocs/op
BenchmarkConcurrentMonotonicArenaNewObject/10000-8                  4714            233151 ns/op               0 B/op          0 allocs/op
BenchmarkConcurrentMonotonicArenaNewObject/100000-8                  598           1939938 ns/op               0 B/op          0 allocs/op
BenchmarkRuntimeMakeSlice/100-8                                    36321             33419 ns/op          204800 B/op        100 allocs/op
BenchmarkRuntimeMakeSlice/1000-8                                    3405            330008 ns/op         2048009 B/op       1000 allocs/op
BenchmarkRuntimeMakeSlice/10000-8                                    362           3354655 ns/op        20480100 B/op      10001 allocs/op
BenchmarkRuntimeMakeSlice/100000-8                                    31          35878034 ns/op        204801102 B/op    100011 allocs/op
BenchmarkMonotonicArenaMakeSlice/100-8                             27572             40248 ns/op               0 B/op          0 allocs/op
BenchmarkMonotonicArenaMakeSlice/1000-8                            23138             48749 ns/op               0 B/op          0 allocs/op
BenchmarkMonotonicArenaMakeSlice/10000-8                            1066           1023822 ns/op               0 B/op          0 allocs/op
BenchmarkMonotonicArenaMakeSlice/100000-8                             26          43787002 ns/op        137691202 B/op     67232 allocs/op
BenchmarkConcurrentMonotonicArenaMakeSlice/100-8                   28334             37244 ns/op               0 B/op          0 allocs/op
BenchmarkConcurrentMonotonicArenaMakeSlice/1000-8                  20376             55866 ns/op               0 B/op          0 allocs/op
BenchmarkConcurrentMonotonicArenaMakeSlice/10000-8                  1039           1123206 ns/op               0 B/op          0 allocs/op
BenchmarkConcurrentMonotonicArenaMakeSlice/100000-8                   25          48233981 ns/op        137691197 B/op     67232 allocs/op
PASS
ok      github.com/ortuman/nuke 36.701s

Benchmark results for this pr:

go test -bench=. ./...
goos: darwin
goarch: amd64
pkg: github.com/ortuman/nuke
cpu: Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
BenchmarkRuntimeNewObject/100-8                   936972              1286 ns/op             800 B/op        100 allocs/op
BenchmarkRuntimeNewObject/1000-8                   91796             13433 ns/op            8000 B/op       1000 allocs/op
BenchmarkRuntimeNewObject/10000-8                   8335            131346 ns/op           80000 B/op      10000 allocs/op
BenchmarkRuntimeNewObject/100000-8                   890           1266103 ns/op          800005 B/op     100000 allocs/op
BenchmarkRuntimeNewObject/1000000-8                   80          12671721 ns/op         8000057 B/op    1000000 allocs/op
BenchmarkMonotonicArenaNewObject/100-8             34165             35619 ns/op               0 B/op          0 allocs/op
BenchmarkMonotonicArenaNewObject/1000-8            24819             46491 ns/op               0 B/op          0 allocs/op
BenchmarkMonotonicArenaNewObject/10000-8            7020            159810 ns/op               0 B/op          0 allocs/op
BenchmarkMonotonicArenaNewObject/100000-8            918           1272404 ns/op               0 B/op          0 allocs/op
BenchmarkMonotonicArenaNewObject/1000000-8            54          21980538 ns/op               0 B/op          0 allocs/op
BenchmarkConcurrentMonotonicArenaNewObject/100-8                   32769             36106 ns/op               0 B/op          0 allocs/op
BenchmarkConcurrentMonotonicArenaNewObject/1000-8                  22920             51180 ns/op               0 B/op          0 allocs/op
BenchmarkConcurrentMonotonicArenaNewObject/10000-8                  5166            207716 ns/op               0 B/op          0 allocs/op
BenchmarkConcurrentMonotonicArenaNewObject/100000-8                  664           1762064 ns/op               0 B/op          0 allocs/op
BenchmarkConcurrentMonotonicArenaNewObject/1000000-8                  45          25286030 ns/op               0 B/op          0 allocs/op
BenchmarkRuntimeMakeSlice/100-8                                    36538             32732 ns/op          204801 B/op        100 allocs/op
BenchmarkRuntimeMakeSlice/1000-8                                    3331            330120 ns/op         2048009 B/op       1000 allocs/op
BenchmarkRuntimeMakeSlice/10000-8                                    352           3387211 ns/op        20480104 B/op      10001 allocs/op
BenchmarkRuntimeMakeSlice/100000-8                                    34          33814642 ns/op        204801126 B/op    100011 allocs/op
BenchmarkRuntimeMakeSlice/1000000-8                                    4         327812672 ns/op        2048010200 B/op  1000106 allocs/op
BenchmarkMonotonicArenaMakeSlice/100-8                             30214             38373 ns/op               0 B/op          0 allocs/op
BenchmarkMonotonicArenaMakeSlice/1000-8                            24309             48698 ns/op               0 B/op          0 allocs/op
BenchmarkMonotonicArenaMakeSlice/10000-8                             991           1085629 ns/op               0 B/op          0 allocs/op
BenchmarkMonotonicArenaMakeSlice/100000-8                             31          35497399 ns/op        137691185 B/op     67232 allocs/op
BenchmarkMonotonicArenaMakeSlice/1000000-8                             3         416722326 ns/op        1980892256 B/op   967243 allocs/op
BenchmarkConcurrentMonotonicArenaMakeSlice/100-8                   31250             37739 ns/op               0 B/op          0 allocs/op
BenchmarkConcurrentMonotonicArenaMakeSlice/1000-8                  21745             54868 ns/op               0 B/op          0 allocs/op
BenchmarkConcurrentMonotonicArenaMakeSlice/10000-8                  1105           1017490 ns/op               0 B/op          0 allocs/op
BenchmarkConcurrentMonotonicArenaMakeSlice/100000-8                   30          40167859 ns/op        137691193 B/op     67232 allocs/op
BenchmarkConcurrentMonotonicArenaMakeSlice/1000000-8                   2         544447913 ns/op        1980891952 B/op   967240 allocs/op
PASS
ok      github.com/ortuman/nuke 50.360s

Benchmarks above are the best of what I can get on my machine.

if you are interested in some specific change I can split this pr.

AnyCPU commented 8 months ago

@ortuman added two new changes, please take a look