Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce memory allocated in DataChannel.readLoop
See pion#1516 This patch preserves the semantics of the OnMessage handler and is more safe but less efficient than the patch first described in pion#1516. As expected, when run with GOMAXPROCS=1 there is opportunity for re-use and syn.Pool is pure overhead. As allocs/op increases due to sync.Pool overhead but B/op and ns/op improve drastically. $ git checkout datachannel.go && \ got test -bench=DataChannelSend -run=XXX \ -benchmem -cpu=1,2,4,8 -count=10 > original.txt $ git checkout datachannel.go && git apply pool.patch && \ go test -bench=DataChannelSend -run=XXX \ -benchmem -cpu=1,2,4,8 -count=10 > patched.txt $ benchstat original.txt patched.txt name old time/op new time/op delta DCSend 1.45µs ±35% 1.24µs ±40% ~ (p=0.211 n=9+10) DCSend-2 885ns ±14% 2221ns ±44% +150.87% (p=0.000 n=10+9) DCSend-4 5.19µs ±15% 3.27µs ±16% -37.13% (p=0.000 n=9+10) DCSend-8 8.07µs ±22% 3.97µs ± 4% -50.78% (p=0.000 n=10+8) name old alloc/op new alloc/op delta DCSend 1.67kB ±72% 0.31kB ±12% -81.55% (p=0.000 n=9+10) DCSend-2 1.80kB ±21% 0.34kB ±14% -81.14% (p=0.000 n=10+8) DCSend-4 1.47kB ±14% 1.40kB ± 0% -4.39% (p=0.031 n=10+8) DCSend-8 2.18kB ±14% 1.45kB ± 0% -33.57% (p=0.000 n=9+8) name old allocs/op new allocs/op delta DCSend 6.00 ± 0% 6.80 ±18% +13.33% (p=0.008 n=8+10) DCSend-2 6.00 ± 0% 8.11 ±36% +35.19% (p=0.000 n=10+9) DCSend-4 7.00 ± 0% 37.00 ± 0% +428.57% (p=0.000 n=10+10) DCSend-8 7.70 ± 9% 39.00 ± 0% +406.49% (p=0.000 n=10+7)
- Loading branch information