file.d icon indicating copy to clipboard operation
file.d copied to clipboard

feat(event pool): simplify realization of event pool

Open ythosa opened this issue 2 years ago • 4 comments

Description

I have managed to improve the performance of the pool and improve its readability

Benchmarks

Old

BenchmarkEventPoolOneGoroutine-8        58460538                19.96 ns/op            0 B/op          0 allocs/op
BenchmarkEventPoolManyGoroutines-8           100          10746244 ns/op            4986 B/op         56 allocs/op
BenchmarkEventPoolSlowestPath-8              152           8189235 ns/op           27087 B/op       1034 allocs/op

New

BenchmarkEventPoolOneGoroutine-8        39543708                32.61 ns/op            0 B/op          0 allocs/op
BenchmarkEventPoolManyGoroutines-8           697           1724738 ns/op             876 B/op         15 allocs/op
BenchmarkEventPoolSlowestPath-8             1026           1038654 ns/op           24619 B/op       1007 allocs/op

ythosa avatar Apr 21 '24 03:04 ythosa

@kirillov6 @goshansmails please review!

ythosa avatar Apr 21 '24 09:04 ythosa

btw, i've tested realisation based on sync.Pool, it was too much faster than my new realisation, but the possibility of event dump was lost

ythosa avatar Apr 22 '24 11:04 ythosa

@ythosa, hello!

You can use BenchmarkLightJsonReadPar to check how the performance has changed. On mac m1 this bench showed following result: old:

BenchmarkLightJsonReadPar-8            1        2256751708 ns/op         643.06 MB/s     4825008 B/op      48384 allocs/op

new:

BenchmarkLightJsonReadPar-8            1        4433031459 ns/op         327.37 MB/s     4272744 B/op      42659 allocs/op

Also, we can't use sync.Pool because insaneJSON uses own global pool. So, we need to refactor insaneJSON first, then we can test sync.Pool

vadimalekseev avatar Apr 26 '24 07:04 vadimalekseev

Wow, I haven't seen this benchmark. You are very cool...

ythosa avatar Apr 26 '24 09:04 ythosa