In addition to slow font enumeration, we were suffering from a similar problem: slow plugin enumeration. Just as with fonts, the plugin enumeration code is different on every platform. Unlike the font situation, plugin enumeration is done completely within our code(ie easy to fix).
- Files in plugin directories are listed
- Platform-specific IsPluginFile function to determines what files look like plugins(ie np*.dll on Windows).
- Code then checks if the files + their timestamps are known by pluginreg.dat. If so, cached info is used and the following steps are skipped
- For each library-file that isn’t found in pluginreg.dat, we use platform-specific GetPluginInfo to load the library-file to see if it is indeed a valid plugin (and to see what mimetypes it handles/etc).
- Valid plugins are recorded in pluginreg.dat.
This process took up to 3 seconds on a user’s computer. WTF? There were gotchas in almost every step of the way.
- Windows directory listing code would request metadata for every bloody file in the directory. Which resulted in an easiest optimization ever: pure code deletion.
- IsPluginFile on Windows/Mac sneakily did more than just check the filename. It also checked if the file was loadable, which on Windows loaded the dll and all of the dependencies. Mac code was satisfied with merely doing a little extra IO.
- This part was right
- #2 was easily fixed by moving file IO here.
- Files that failed the check in #4 were doomed to cause extra IO for all of eternity. Scott Greenlay fixed that by recording invalid plugin-like files too.
This was a rare fix that resulted in seconds saved on crapware-loaded computers. Usually I have to count my progress in milliseconds 🙁
I have plans for vastly improving Firefox startup, but I need help to get there. If you enjoy beating under-performing code into submission and want to work for Mozilla, please send me your resume(taras at mozilla dot com). Example projects: a better performance testsuite (ie tracking IO, cpu instructions, etc), better infrastructure for profiling addons, optimizing away various CSS/XUL markup, etc. A low-level approach to solving problems is helpful, compiler/linker/kernel hackers are well-suited (but not required) for this.