[sword-devel] Question for Optimization / speed experts

Joachim Ansorg sword-devel@crosswire.org
Mon, 6 Jan 2003 14:46:27 +0100

Some questiosn for optimizations experts :)

I'm working on a piece of code in BibleTime which gives me headaches.
BibleTime supports displaying different lexicons side by side, it offers only 
the keys which are available in all of the chosen lexicons.

The function which creates the list of entries which  are available in all 
modules is ways too slow and too CPU consuming.
I implemented it the following way:

 1. Sort the modules by number of entries (from small to large)
 2. Use the modules with the fewest entries and go through all of it's 
	 3. Is the entry in all other modules? Add the entry to a list of good 
entries it it is, otherwise continue with the next entry of the smallest list 
and compare it with all other chosen modules.

Assume the user selected BDB together with StrongsHebrew. Each of the modules 
has around 10000 entries. So the outer loop would have 10000 iterations, the 
inner loop would have another 10000 iterations. So we get 
10.000*10.000=100.000.000 = one hunred million iterations. This is ways too 
slow and ways too much.
This needs on my 1.2GHz Atlon with 512 MB Ram more then five seconds. 

If there are three, four or even five modules side by side we get much more 

Are the other ways to do such a task? Since the entry lists are sorted by the 
alaphabet this would be a good point to start. But I don't know how to do it 

I'd be really glad for help with this case!

Thank you!
Joachim Ansorg