sipsorcery
sipsorcery copied to clipboard
Reduce Memory allocations
Reduce Memory allocations on H264 Sender HotPath by reusing byte[] and using ArrayPool
I feel overloading is better than refactoring the method since it is public, minimizing breaking changes.
Then use the optimized overload for any internal use.
Thanks for the PR. it does look like a big improvement.
Along the same lines as @ha-ves would it be possible to have this somehow opt-in for a bedding in period? Maybe behind a pre-processor directive. It would be good to get some confidence that there are no side effect before throwing it into the wild.
I am currently working on readding the older method signatures. do we have some tests to make sure, no side effects are there?
Just heads up @weltmeyer , @sipsorcery I have a much larger work in the same vein here: https://github.com/BorgGames/sipsorcery
It gives 40MB/s data channel bandwidth vs 10MB/s on the same machine with the current master. It also includes BouncyCastle 2 changes. I am generally interested in trying to merge it, if you guys are OK to review a PR of this size.
It does introduce breaking API changes though. (In a way it is inevitable - if your app that consumes SIPSorcery overrides one of the classes that takes T[] to change some behavior, there's no way it could be supported when the base class switches to Span<T>)
I am currently working on readding the older method signatures. do we have some tests to make sure, no side effects are there?
thre public api should now also function with the old calls - except the NAL parser, but i dont know if this needs to be public at all.
I am currently working on readding the older method signatures. do we have some tests to make sure, no side effects are there?
I would suggest doing benchmarks since it's an optimization.
Basic Benchmark.NET should show enough comparison.
Thanks for the PR!
There seems to be a build failure in the latest commit.
Severity Code Description Project File Line Suppression State Details
Error (active) CS0535 'SrtpTransformer' does not implement interface member 'IPacketTransformer.Transform(byte[], int, int)' SIPSorcery (net461), SIPSorcery (net5.0), SIPSorcery (net6.0), SIPSorcery (net8.0), SIPSorcery (netcoreapp3.1), SIPSorcery (netstandard2.0), SIPSorcery (netstandard2.1) C:\Dev\github\sipsorcery\src\net\DtlsSrtp\Transform\SrtpTransformer.cs 48
Error (active) CS0535 'SrtpTransformer' does not implement interface member 'IPacketTransformer.Transform(byte[], int, int)' SIPSorcery (net461), SIPSorcery (net5.0), SIPSorcery (net6.0), SIPSorcery (net8.0), SIPSorcery (netcoreapp3.1), SIPSorcery (netstandard2.0), SIPSorcery (netstandard2.1) C:\Dev\github\sipsorcery\src\net\DtlsSrtp\Transform\SrtpTransformer.cs 48
Error (active) CS0535 'SrtpTransformer' does not implement interface member 'IPacketTransformer.Transform(byte[])' SIPSorcery (net461), SIPSorcery (net5.0), SIPSorcery (net6.0), SIPSorcery (net8.0), SIPSorcery (netcoreapp3.1), SIPSorcery (netstandard2.0), SIPSorcery (netstandard2.1) C:\Dev\github\sipsorcery\src\net\DtlsSrtp\Transform\SrtpTransformer.cs 48
Error (active) CS0535 'SrtpTransformer' does not implement interface member 'IPacketTransformer.Transform(byte[])' SIPSorcery (net461), SIPSorcery (net5.0), SIPSorcery (net6.0), SIPSorcery (net8.0), SIPSorcery (netcoreapp3.1), SIPSorcery (netstandard2.0), SIPSorcery (netstandard2.1) C:\Dev\github\sipsorcery\src\net\DtlsSrtp\Transform\SrtpTransformer.cs 48
Thanks for the PR!
There seems to be a build failure in the latest commit.
Severity Code Description Project File Line Suppression State Details Error (active) CS0535 'SrtpTransformer' does not implement interface member 'IPacketTransformer.Transform(byte[], int, int)' SIPSorcery (net461), SIPSorcery (net5.0), SIPSorcery (net6.0), SIPSorcery (net8.0), SIPSorcery (netcoreapp3.1), SIPSorcery (netstandard2.0), SIPSorcery (netstandard2.1) C:\Dev\github\sipsorcery\src\net\DtlsSrtp\Transform\SrtpTransformer.cs 48 Error (active) CS0535 'SrtpTransformer' does not implement interface member 'IPacketTransformer.Transform(byte[], int, int)' SIPSorcery (net461), SIPSorcery (net5.0), SIPSorcery (net6.0), SIPSorcery (net8.0), SIPSorcery (netcoreapp3.1), SIPSorcery (netstandard2.0), SIPSorcery (netstandard2.1) C:\Dev\github\sipsorcery\src\net\DtlsSrtp\Transform\SrtpTransformer.cs 48 Error (active) CS0535 'SrtpTransformer' does not implement interface member 'IPacketTransformer.Transform(byte[])' SIPSorcery (net461), SIPSorcery (net5.0), SIPSorcery (net6.0), SIPSorcery (net8.0), SIPSorcery (netcoreapp3.1), SIPSorcery (netstandard2.0), SIPSorcery (netstandard2.1) C:\Dev\github\sipsorcery\src\net\DtlsSrtp\Transform\SrtpTransformer.cs 48 Error (active) CS0535 'SrtpTransformer' does not implement interface member 'IPacketTransformer.Transform(byte[])' SIPSorcery (net461), SIPSorcery (net5.0), SIPSorcery (net6.0), SIPSorcery (net8.0), SIPSorcery (netcoreapp3.1), SIPSorcery (netstandard2.0), SIPSorcery (netstandard2.1) C:\Dev\github\sipsorcery\src\net\DtlsSrtp\Transform\SrtpTransformer.cs 48
Sorry for that. it is in now :)
Thanks, build is good now.
There are 4 unit test failures which I suspect are related to a new bug. The test all pass on he master branch.
@weltmeyer I've opened a PR in #1212 to revert this PR as it's causing corruption on audio streams.
The easiest was to replicate the issue is to use the SIP examples:
- Start
examples\SIPExamples\SIPCallServerusingdontnet run - Start the UserAgentClient
examples\SIPExamples\UserAgentClientusingdotnet run sip:[email protected]
With #1190 the stream is barely recognisable as music.