hidapi icon indicating copy to clipboard operation
hidapi copied to clipboard

hidapi/libusb: maintain in-memory cache of vendor/product strings

Open slouken opened this issue 2 years ago • 8 comments

The get_usb_string call is rather expensive on some USB devices, so we cache the vendor/product strings for future lookups (e.g. when hid_enumerate is invoked again later).

This way, we only need to ask libusb for strings for devices we haven't seen since before we started.

This is an important performance improvement when frequently iterating devices using libusb.

slouken avatar May 26 '23 16:05 slouken

What about serial_number? Shouldn't it be cached as well?

Youw avatar Jun 01 '23 15:06 Youw

And the caching probably needs to be device-specific, not vid/pid-specific. I have two USB/HID devices on my table right now: both have the same vid/pid but different Manufacturer and Product Name (FW is localized for different countries).

Youw avatar Jun 01 '23 15:06 Youw

I also think none of it would be required when https://github.com/libusb/libusb/pull/1258 is completed.

Youw avatar Jun 01 '23 15:06 Youw

And the caching probably needs to be device-specific, not vid/pid-specific. I have two USB/HID devices on my table right now: both have the same vid/pid but different Manufacturer and Product Name (FW is localized for different countries).

Good point.

slouken avatar Jun 01 '23 15:06 slouken

Unfortunately https://github.com/libusb/libusb/pull/1258 is closed without being merged, due to some API discussions.

  • https://github.com/libusb/libusb/pull/1258

mcuee avatar Mar 06 '24 05:03 mcuee

But the idea to get is done is still alive. It is just a matter of getting it done. I'd rather spend time making that than improving the change in this PR.

Youw avatar Mar 06 '24 11:03 Youw

But the idea to get is done is still alive. It is just a matter of getting it done. I'd rather spend time making that than improving the change in this PR.

Good point. I agree with you here.

In that case, do you want to close this PR as not planned?

mcuee avatar Mar 06 '24 12:03 mcuee

I don't have a strong oppinion. It doesn't bother me having it open.

Youw avatar Mar 06 '24 13:03 Youw