Comments (2)
I am not sure if this actually improves things:
var crc32Table = crc32.MakeTable(crc32.Castagnoli)
func generatePacketChecksumNew(raw []byte) uint32 {
chksum := crc32.New(crc32Table)
chksum.Write(raw[:8])
chksum.Write([]byte{0x00, 0x00, 0x00, 0x00})
chksum.Write(raw[12:])
return chksum.Sum32()
}
func generatePacketChecksumOld(raw []byte) uint32 {
rawCopy := make([]byte, len(raw))
copy(rawCopy, raw)
// Clear existing checksum
for offset := 8; offset <= 11; offset++ {
rawCopy[offset] = 0x00
}
return crc32.Checksum(rawCopy, crc32.MakeTable(crc32.Castagnoli))
}
var (
testPacket = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
)
func BenchmarkNew(b *testing.B) {
for n := 0; n < b.N; n++ {
generatePacketChecksumNew(testPacket)
}
}
func BenchmarkOld(b *testing.B) {
for n := 0; n < b.N; n++ {
generatePacketChecksumOld(testPacket)
}
}
archlinux% go test -run=XXX -bench=. -benchtime=20s
goos: linux
goarch: amd64
pkg: github.com/pion/sctp
BenchmarkNew-12 352351734 71.2 ns/op
BenchmarkOld-12 656112110 37.6 ns/op
PASS
ok github.com/pion/sctp 60.301s
Unless there is a more efficient way to use the io.Writer
interface of crc32
then I don't think it will be more efficient. The .crc32.Write
method is an interface call, compared to a copy/replace of a few bytes. Tbh though - I don't think the copy is needed at all. We should be able to write the 0x00
bytes into the original packet and calculate the crc32 directly. I'm not seeing any where in the code that would dislike this.
I.e. (untested, but I can't see what is stopping us from using this):
func generatePacketChecksumOld(raw []byte) uint32 {
// Clear existing checksum
for offset := 8; offset <= 11; offset++ {
raw[offset] = 0x00
}
return crc32.Checksum(raw, crc32.MakeTable(crc32.Castagnoli))
}
from sctp.
Oh hey @AeroNotix, I didn't realize you looked into this already. Could you take a look at my pull request and see if it looks better? I can explain what was wrong with your benchmark and new implementation if you'd like.
from sctp.
Related Issues (20)
- panic in Association.handleCookieEcho HOT 1
- What is the difference with Linux SCTP? HOT 2
- Changing initialRecvBufSize causes datachannel to hang
- Dependency Dashboard
- SACK chunks followed by other chunks are incorrectly handled. HOT 2
- Datachannels have a great latency for poor network HOT 9
- SCTP throughput ~8x slower than TCP when the connection has latency HOT 15
- User Initiated Abort (cause code: 12) not handled HOT 3
- Remove the pending buffer after the data channel call close() by either side. HOT 12
- SCTP Streams have no SetReadDeadline
- Race in TestStreamClose introduced by the previous merge
- Potential regression by a commit c0159aa in causing `TestAssociation_Shutdown` to fail HOT 5
- Expose error definitions HOT 6
- SCTP support capabilities HOT 1
- Document planned / implemented RFCs in README
- Flaky tests and/or goroutine leaks HOT 8
- Panic occured on one way data transmission through Client to Client stream
- sctp.Read sometimes returns DeadlineExceededError on past cancelled deadlines HOT 1
- v2 Plans HOT 5
- No reliable way to be notified of a Stream buffer becoming empty HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sctp.