[sane-devel] sane_get_devices() is very slow
Henning Meier-Geinitz
henning at meier-geinitz.de
Sat Feb 15 19:07:56 GMT 2003
Hi,
On Thu, Feb 13, 2003 at 02:49:40PM -0800, Derry Bryson wrote:
> I am thinking along the lines of keeping a list around, but allowing the
> user the option to detect devices when selecting a source. This I can do
> in my code without needing to change the sane API.
I don't really understand. What source are you talking about? So you
mean the scanner (or other image application device)? "source" in SANE
ususally means "flatbed", "ADF" or "Transparency adapter".
> If you were to want to consider changing the API,
There will be an API change in SANE2, but I don't think it's necessary
in the case we are talking about.
> I might suggest adding a sane_list_devices() function with the same
> signature as sane_get_devices() that would be implemented in most
> backends as a call to sane_get_devices(), but in the dll and net
> backends would return the list of devices cached from the last call
> to sane_get_devices(). The cached list would saved to a file when
> the backend is unloaded and read when the backend is loaded.
Why? In this case, new devices aren't found and unplugged or powered
off devices are still displayed as "live". I think that's broken.
During runtime the list of devices is "cached", i.e. sane_init of a
backend is only called when necessary.
Here is some simple test code:
stopwatch (sane_init (&version_code, NULL));
stopwatch (sane_get_devices (&device_list, SANE_TRUE));
stopwatch (sane_get_devices (&device_list, SANE_TRUE));
stopwatch (sane_get_devices (&device_list, SANE_FALSE));
stopwatch (sane_get_devices (&device_list, SANE_FALSE));
stopwatch (sane_exit ());
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
So the second call of sane_get_devices is much faster than the first
one (as intended). The third one also checks for network scanners and
take a bit longer therefore. But the forth one now knows the network
scanners and is faster again.
This is 0.221 seconds (221 miliseconds) we are talking about and this
time is only necessary once per sane_init (program start, not scan).
Bye,
Henning
More information about the sane-devel
mailing list