HidLibrary icon indicating copy to clipboard operation
HidLibrary copied to clipboard

Performance problem

Open piratezstick opened this issue 10 years ago • 6 comments

Hi,

I'm having a bit of a problem with the performance. I am receiving a lot of data and when I do that my cpu is at 100%.

I ran the Visual Studio performance profiler and it says that 90% of the load come from here:

public HidDeviceData Read(int timeout) if (IsConnected)

And then 80% from here:

        NativeMethods.SetupDiGetDeviceRegistryProperty(deviceInfoSet,
                                                        ref devinfoData,
                                                        NativeMethods.SPDRP_DEVICEDESC,
                                                        ref type,
                                                        descriptionBuffer,
                                                        descriptionBuffer.Length,
                                                        ref requiredSize);

It seems like it is doing a lot of stuff while trying to find out if the device is still connected? Is it necessary to do all of that before every read?

Or did I missunderstand something?

piratezstick avatar Jun 13 '14 22:06 piratezstick

Not really sure. I wrote this almost a decade ago for a project so I can't remember why it was setup that way.

mikeobrien avatar Jun 16 '14 16:06 mikeobrien

I Had the same issue, plase take a look at my solution here: https://github.com/mikeobrien/HidLibrary/issues/11

kaczart avatar Mar 05 '15 09:03 kaczart

Please see my solution too: https://github.com/mikeobrien/HidLibrary/issues/11#issuecomment-170944469

macaba avatar Jan 12 '16 15:01 macaba

I recently changed my project from another Hid library towards the HidLibrary because of issues in unit testing that were not fixed. It was not too complicated to migrate the project and it's up and running right now. The first tests showed a stable communication.

The only thing I'm struggeling is that writing many data over Hid reports is very slow. A google search brought me to this issue and I assume that this also is the problem in my case.

As far as I see there is no way of fixing this performance issue with the official version from the NuGet server, right? It seems that the only solutions proposed above are implemented on forks or copies of the HidLibrary.

Are there any plans to add a possibility to "ignore" the IsConnected check?

AdrianEggenberger avatar Oct 20 '20 06:10 AdrianEggenberger

The HidFastReadDevice class essentially replicates the HidDevice class but skips the IsConnected check. This is already part of the library, so I feel like we could close this issue if that solves your problem.

amullins83 avatar Oct 20 '20 14:10 amullins83

I've seen that, but the HidFastReadDevice only provides fast read functions (as the name also implies). What I would need is a HidFastWriteDevice that provides fast write operations.

AdrianEggenberger avatar Oct 20 '20 14:10 AdrianEggenberger