GNOME Bugzilla – Bug 587089
lookup_attribute() takes too much CPU
Last modified: 2009-06-30 07:32:28 UTC
When enumerating local files in the file chooser, almost 1/3rd of the CPU is taken by lookup_attribute() calls, with equal time taken by g_file_attribute_matcher_matches() and g_file_info_create_value_by_name(). As this is internal to gio, it seems like a worthwhile optimization to me to add hard-coded integer IDs for all the content types gio has a #define for and use those ids in the local file enumeration instead of looking them up all the time. If that sounds like a good idea, I'll prepare a patch. (Note: This bug is not about adding public API to use those IDs, but only about speeding up glocalfileinfo.c's g_local_file_info_get() function)
It sounds reasonable to me
All attributes are stored as ints internally. Maybe we can just expose lookup_attribute() as a public GQuark-style thing. Of course, this does not imply we can't have #defines for some predefined set of attributes too.
Created attachment 137560 [details] [review] split attribute hash initialization into its own function
Created attachment 137561 [details] [review] split attribute hash initialization into its own function
Created attachment 137562 [details] [review] split lookup_attribute() into two functions
Created attachment 137563 [details] [review] add private header with attribute ids attribute ids are generated when the attribute hash is initialized. This way we can guarantee that the ids match every time.
Created attachment 137564 [details] [review] export and use _g_file_attribute_matcher_matches_id()
Created attachment 137565 [details] [review] add g_file_attribute_set_*_by_id() and use them This patch and the previous ones fixes the performance issues noted in Bug 587089 – lookup_attribute() takes too much CPU It increases performance for querying attributes by ~15% in my tests.
Here's a bunch of patches that implements this. I put it into a private header - gfileinfo-priv.h - because I'm not sure exporting this implementation detail is a good idea. Ok to commit?
Looks good, please commit.
pushed to master