[sane-devel] sane_get_devices() is very slow

Henning Meier-Geinitz henning@meier-geinitz.de
Mon, 17 Feb 2003 23:28:54 +0100


Hi,

On Sat, Feb 15, 2003 at 03:13:14PM -0800, Derry Bryson wrote:
> First, a front-end could choose to always use sane_get_devices() to
> force a check.  Second, a program could be written to update the
> cache file that can be run at system startup, at anytime by the
> user after adding or removing a device, and whenever a usb device
> is added or removed.  Third, the front-end could be written to allow 
> the user to select redetection when selecting a device (i.e. an 'Update 
> Devices' button on the device selection dialog).

If a frontend really wants to cache the devices, it can do that with
the current API. Just call sane_get_devices once and save the
information (including the device names) to a file. When starting the
next time, reload this information and don't call sane_get_devices but
display the list from the file, let the user select and call e.g.
sane_open ("mustek:/dev/sg0") directly. This way, only sane_init of
the mustek backend is called. I don't recomend to do that, however.
Even if you only have one device, you may want to turn it off if it's
not used and it will have a new libusb name when it is turned on
again.

> It would allow the front-end to allow the user to determine whether
> or not to spend time looking for new devices.  Most people probably
> don't plug and unplug their scanner often and should not have to
> wait for it to be redetected everytime they want to scan.

My experience is that if you use caching for anything that can't
detect automatically when to refresh the cache you will get a support
nightmare. ("Yesterday my scanner worked and today it isn't found?")

Let's fix the bugs (slow detection) and don't create workarounds that
will bite us in the back.

> > The macro "stopwatch" times the function that's given as argument.
> > So we call sane_init, get the device list twice, and then get the
> > device list including the devices not locally connected. I have one
> > USB and one SCSI scanner connected. Result:
> > 
> > sane_init (&version_code, NULL) took 0.000 seconds
> > sane_get_devices (&device_list, SANE_TRUE) took 0.134 seconds
> > sane_get_devices (&device_list, SANE_TRUE) took 0.014 seconds
> > sane_get_devices (&device_list, SANE_FALSE) took 0.221 seconds
> > sane_get_devices (&device_list, SANE_FALSE) took 0.029 seconds
> > sane_exit () took 0.003 seconds
> 
> Certainly you are correct once the front-end has called sane_get_devices() the
> first time, calls after that will be fast.  But this is irrelevant if you
> want to detect new devices everytime, correct?  Also, each front-end must do 
> the same thing and each must wait for devices to be detected.  

Maybe that's a difference in philosopy. I want to have software that
works with as little user intervention as possible. So I don't like
installing drivers for every single piece of software and I don't even
like pressing buttons when I plug in a USB device.

> I upgraded to 1.0.11 and it is much better at just over 7 seconds (vs. 36 seconds 
> with 1.0.5).  Obviously your computer is much faster than mine.

The timings above are done on a Athlon 1400. Here is the same test
with a Pentium 366. This time without network access. One USB-Scanner
and a v4l card connected. This is with the old scanner driver, so the
syslog is cluttered with messages (slows down everything a bit). Both
tests are without devfs.

sane_init (&version_code, NULL) took 0.001 seconds
sane_get_devices (&device_list, SANE_TRUE) took 0.368 seconds
sane_get_devices (&device_list, SANE_TRUE) took 0.001 seconds
sane_get_devices (&device_list, SANE_FALSE) took 0.001 seconds
sane_get_devices (&device_list, SANE_FALSE) took 0.001 seconds
sane_exit () took 0.002 seconds

Still ok in my opinion.

Do you use devfs? Which kernel version? Which type of computer do you
use?

Bye,
  Henning