possible optimizations in Script-Fu regarding startup
Submitted by Sven Neumann
Link to original bug (#374854)
Description
1 - It appears that Script-Fu parsing its scripts takes up about one third of the startup time of gimp (with warm caches). I had a look at this with sysprof and found that about two third of that time is spent in oblist_find_by_name(). This function spends almost all of its time comparing strings. It does so in a case-insensitive way that is suitable for UTF-8 encoded strings. In particular it calls g_utf8_casefold() on both strings and compares them with g_utf8_collate(). The latter needs to do normalize the strings before comparing them.
If we could store the normalized casefolded string in the table that oblist_find_by_name() searches in, we could avoid doing the casefolding and normalization for at least one of the strings. A lot of other places also call stricmp(), but almost always with lowercase ASCII strings which can be assumed to be identical to their casefolded and normalized version.
As far as I can see the stored strings are even already normalized (not case-folded though), see store_string(). Now if we could also case-fold them, we could cut down startup time noticeably with a simple change.
2 - Other optimizations are possible as well. For example it appears as if the string length passed to store_string() is a character count that needs to be calculated using g_utf8_strlen(). The value is then immidiately converted back to a bytes count in store_string().
It is also questionable whether it makes sense to copy all glib-allocated strings to newly malloced buffers. It may make sense to do all memory allocation using g_malloc() and friends and then just use the strings that glib allocated for us. This would avoid some redundant memory allocations and copies.
Version: git master