eglaysher / rlvm

RealLive clone for Linux and OSX
http://rlvm.net
GNU General Public License v3.0
152 stars 26 forks source link

10% of runtime is spent in findFile on a normal rlvm run. #9

Closed eglaysher closed 13 years ago

eglaysher commented 13 years ago

findFile is completely bogus. It is pathologically bad.

The outer loop in findFile iterates every listed directory with a #FOLDNAME. Multiply that by then testing every candidate file extension. And then performing a complex case sensitive matching algorithm on every candidate path. (boost::to_upper takes up 3% of runtime!)

So run an expensive algorithm over a naive search that looks at /.. This is a recipe for SLOW.

Action plan: 1) Nobody should use or call ALL_FILETYPES. Ugh. Obvious bad idea in retrospect. 2) If the script is looking for GAN files, perhaps we should only try to look in the GAN/ directory first. 3) If still needed, we could probably do something about the correctPathCase(), which takes up the vast majority of time in findFile(), but only because findFile() keeps calling it over and over again.

eglaysher commented 13 years ago

Reimplement findFile().

Profiling showed that 10% of runtime was spent in findFile(), which searched the filesystem over and over for each listed directory/extension combination. In retrospect, it was pathologically bad.

Implement a new version which iterates over the directory tree of the game first, lower cases path components so we don't do the expensive correctCase(), and then returns from this cache instead of going to disk (and doing the expensive directory iteration on each try).

Closed by 1cd873847ae834585f9edd723bf3a253ef982b7a