[sane-devel] sane_get_devices() is very slow

Derry Bryson dbryson at techass.com
Wed Feb 19 18:38:30 GMT 2003


Henning Meier-Geinitz wrote:
> 
> There have been two problems that made the detection slower than
> necessary:
> 
> a) The kernel scanner driver prints a message everytime a device file
>    is opened that isn't connected to an actual scanner. This slows
>    down the detection if done often.
>    Solution: The message isn't printed anymore in recent kernels
>    Workaround: Reduced the number of tests (one per backend, not one
>    per scanner) in sanei_usb
>    Workaround: Reduce the number of tested device files (currently 34).
>    Not implemented.
>    Workaround: Remove unused device files in /dev/usb. Can be done by
>    the user.
> b) If devfs (device filesystem) is enabled, opening non-existant files
>    in /dev is very slow because devfs tries to be clever and searches for
>    the correct driver for this device file.
>    Solution: Scan the directory before blindly opening files. Done in
>    sanei_usb now.
> 
> > I am testing on a 400mhz Celeron with 96MB RAM running RH7.2 (which had
> > SANE 1.0.5 installed by default), not using devfs, kernel version 2.4.7,
> > no actual scanners installed (default dll.conf with pnm backend added).
> > My timing is by stopwatch starting when I select 'Select Source' in my
> > app and stopping when the dialog appears with a list of devices.  Since
> > dialogs generally appear nearly instantaneously, most of the time is being
> > spent in sane_get_devices().  I can record similar times using Xsane so
> > I do not think my code is at fault.  What I am measuring is the actual
> > user experience.
> 
> I did the same with xsane and the times match my test program (+ a
> little overhead for opening the windows, but that's about 0.7 seconds).
> So I think my test program measures correctly.
> 
> I did some more checks with other kernels, e.g. 2.2.19, 2.4.7,
> 2.4.21-pre3 + devfs. None take longer than 0.6 seconds. The first test
> takes longer usually, (1.5 - 2 seconds), but that's because of loading
> the shared libraries.
> 
> > I am looking at this from the point of view of distributing software that
> > could be installed on systems by various non-guru users.  By default (on RH7.2),
> > I would be looking at a 36 seconds wait before the user would be presented
> > with list of devices.  If I request they update and install version 1.0.11,
> > they would still have to wait 7 seconds.  This will be faster or slower depending
> > on their hardware, of course.
> 
> There must be something else that slows down the test. How long does
> it take if you don't load the scanner module? If it's faster without
> the kernel scanner driver, it's because of the messages printed to
> syslog.
> 
> Are syslog messages printed to e.g. xconsole? That may slow down
> things a bit.
> 

I removed all the USB devices from /dev (actually just renamed the directory)
and it is now nearly instantaneous  (certainly much less than a second).  And
you are correct, there are a number of messages (114) appearing in the log concerning
missing modules which don't appear with the usb devices removed.

I don't want to press the suggested API change any further.  It was only a suggestion
and it can easily be implemented outside of SANE by the app.  Thanks for your time
in discussing this.

Derry Bryson



More information about the sane-devel mailing list