Why is the C# API 'slow'

An off-topic general discussion forum to chat about ANYTHING!
Search

Post Reply
3 posts • Page 1 of 1
User avatar
fmulder
Posts: 320
Joined: Wed Feb 03, 2010 9:46 am

Why is the C# API 'slow'

Post by fmulder »

Hi there.

I'm developing a manager using the C# API. This is working nicely (and much easier compared to using the C++ API). However. I found that certain functions are slower than expected.

Example:
* I tried with '-rcv 2' and see that my manager receives the dp container
* still, a function like 'dpTypeName = dataModel.GetDpTypeNameOfDp(dp.Dp );' is relatively slow ?

Does anyone have an explanation.

Can someone explain my why these functions all have an 'async' version. ( like GetDpTypeNameOfDpAsync() ). I would expect the manager to have the dp container in-memory. Why would you need an async version of these functions ?

hope ayone has an answer

Share the fun
Frenk Mulder

User avatar
kilianvp
Posts: 422
Joined: Fri Jan 16, 2015 10:29 am

Re: Why is the C# API 'slow'

Post by kilianvp »

All C# functions are only C++ wrappers. All the wrappers cost more time in execution.

When you call the function GetDpTypeNameOfDp(dpName), internally GetDpTypeNameOfDpAsync(dpName).GetAwaiter().GetResult(); is called.

User avatar
clicht
Posts: 24
Joined: Tue Aug 03, 2010 8:11 am

Re: Why is the C# API 'slow'

Post by clicht »

The whole API is by design asynchronous.
Also information coming from DP-Identification is asynchronous implemented.
The synchronous methods are just synchronized versions of the asynchronous.
I recommend to use always the asynchronous!.

The asynchronous style of implementation has the big benefit, that it can be used in multithreaded environment.
In common the C# API is thread-safe in sense of calling API methods. The synchronization of the response is in the responsibility of usage code.
The inner communication with EVENT is solved in own thread.

Regarding performance:
What is faster depends on what are you comparing.
If you compare a multithreaded access in C# with a single threaded access in C++ for a single method it is impossible that C# is as fast as C++.
For a single operation C# is on top of C++ it can't be faster.
If your application has to do much things in parallel and have to deal with a lot of data, then the multithreading possibilities of C# API can be faster.
But also that depends on the implementation.

I think the big benefit of C# API, compared to C++ API, is the much easier usage and the possibility to use in multithreaded applications with the help of the big .NET extension package universe.

Post Reply
3 posts • Page 1 of 1