1
0
Fork 0
forked from External/mediamtx

rtmp: improve performance

reuse existing structs instead of allocating them during every read()
This commit is contained in:
aler9 2022-08-15 15:42:16 +02:00
parent 4f023b25e8
commit 0db2d3eb8c
3 changed files with 91 additions and 66 deletions

View file

@ -1,6 +1,7 @@
package rtmp
import (
"bytes"
"net"
"net/url"
"testing"
@ -1210,3 +1211,32 @@ func TestWriteTracks(t *testing.T) {
Payload: []byte{0x12, 0x10},
}, msg)
}
func BenchmarkRead(b *testing.B) {
var buf bytes.Buffer
for n := 0; n < b.N; n++ {
buf.Write([]byte{
7, 0, 0, 23, 0, 0, 98, 8,
0, 0, 0, 64, 175, 1, 1, 2,
3, 4, 1, 2, 3, 4, 1, 2,
3, 4, 1, 2, 3, 4, 1, 2,
3, 4, 1, 2, 3, 4, 1, 2,
3, 4, 1, 2, 3, 4, 1, 2,
3, 4, 1, 2, 3, 4, 1, 2,
3, 4, 1, 2, 3, 4, 1, 2,
3, 4, 1, 2, 3, 4, 1, 2,
3, 4, 1, 2, 3, 4, 1, 2,
3, 4, 1, 2, 3, 4, 1, 2,
3, 4, 1, 2, 3, 4, 1, 2,
3, 4, 1, 2, 3, 4, 1, 2,
3, 4, 1, 2, 3, 4,
})
}
conn := NewConn(&buf)
for n := 0; n < b.N; n++ {
conn.ReadMessage()
}
}