none
Socket.cs bad performance when used in another assembly RRS feed

  • Question

  • Hi

    I copied the code of System.Net.Sockets.Socket and all the classes/structs it depends on into my own assembly. I wanted to improve performance by feeding the send/receive routines unmanaged buffers directly (without having to copy and GC-pin them).

    To my surprise my application became almost twice as slow by using these Socket-copy classes. The code is identical to what is found on referencesource and I checked the pinvokes in ilspy, looks the same. What could be the cause of this? Is there anything special about the System assemblies that make them run faster?

    Wednesday, August 28, 2019 10:34 AM

Answers

  • Hi exstud,

    Thank you for posting here.

    >>my application became almost twice as slow by using these Socket-copy classes.

    I regret that we cannot reproduce your problem based on your description.

    I have found a reference about high performance socket server.

    C# SocketAsyncEventArgs High Performance Socket Code 

    Besides, if I have any misunderstandings, please provide more details here.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by exstud Tuesday, September 3, 2019 7:02 AM
    Monday, September 2, 2019 10:02 AM
    Moderator

All replies

  • Hi exstud,

    You are trying to implement this class as part of your own assembly, whereas few system assemblies are available from GAC.

    Your code might need some optimization, but first of all you need to check how the assemblies are loaded into App Domain.

    This conversation may give you some more clarification. 


    Avik Das

    Wednesday, August 28, 2019 11:11 AM
  • The assembly is not in the GAC, it's a regular unsigned dll which is referenced by a console app. It's a release build with optimization enabled. I did notice System.dll has some attributes defined like 'SkipVerificationInFullTrust', tried adding those to my assembly but it didn't help it. 
    Wednesday, August 28, 2019 12:45 PM
  • Hi exstud,

    Thank you for posting here.

    >>my application became almost twice as slow by using these Socket-copy classes.

    I regret that we cannot reproduce your problem based on your description.

    I have found a reference about high performance socket server.

    C# SocketAsyncEventArgs High Performance Socket Code 

    Besides, if I have any misunderstandings, please provide more details here.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by exstud Tuesday, September 3, 2019 7:02 AM
    Monday, September 2, 2019 10:02 AM
    Moderator
  • I tried to reproduce it in a small application but failed. There must be something else, you can close this now, sorry.
    Tuesday, September 3, 2019 7:02 AM