mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-23 12:49:35 -10:00
The web socket protocol uses a 4-byte mask sent from client to server and xor'd with the payload data. In the managed web socket implementation, that mask is currently applied byte-by-byte. This commit changes it to be done using SIMD. Micro-benchmarks on the ApplyMask function itself show a regression for payload lengths under 4 bytes, but above that it's a clear win: ``` 1: 0.44x 3: 0.64x 4: 1.15x 7: 1.16x 31: 1.73x 32: 6.06x 63: 3.37x 64: 10.40x 1024: 20.36x ``` This doesn't have a measurable affect on small payloads in the overall context of sending/receiving data, but the larger the payload, the more it applies. Locally I measured upwards of a 10% improvement for payloads several-K in size. Commit migrated from https://github.com/dotnet/corefx/commit/c73b5ebc1eb92ae5b674fbfc3e871bfc61d2b4aa