You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
component.mt:_element is called hundreds of thousand of time per minute. It is where the Awesome spend ~50% of its time (LGI account for up to 97% of the Lua time). Speed has gotten better since 0.6, but it is still not enough. Here is some proposed changes. I would also have idea how to better reduce the numbers of calls (this only make them less expensive).
Here are some proposed changes and questions:
localmatch_cache= {}
-- Retrieves (element, category) pair from given componenttable and-- instance for given symbol.functioncomponent.mt:_element(instance, symbol)
-- This generic version can work only with strings. Everything else-- will cause an error. It is better to let it happen as this is an-- hot code path and type() is slow-- Check keyword translation dictionary. If the symbol can be-- found there, try to lookup translated symbol.--QUESTION: Is this really necessary? When does this happen--symbol = keyword_dictionary[symbol] or symbol-- Check whether symbol is directly accessible in the component.localelement=rawget(self, symbol)
ifelementthenreturnelementend-- Decompose symbol name, in case that it contains category prefix-- (e.g. '_field_name' when requesting explicitely field called-- name).localcategory, name=nil, nil-- string.gmatch is quite slow and the pool of symbol is quite small-- it seem preferable to cache them given this method is the most called-- by LGIlocalcached_symbol=match_cache[symbol]
ifnotcached_symbolthencategory, name=string.match(symbol, '^(_.-)_(.*)$')
cached_symbol= {category, name}
match_cache[symbol] =cached_symbolelse-- Cannot use unpack() as the table may be sparse and it is undefinedcategory, name=cached_symbol[1], cached_symbol[2]
endifcategoryandnameandcategory~='_access' then-- Check requested category.localcat=rawget(self, category)
element=catandcat[name]
elseifstring.sub(symbol, 1, 1) ~='_' then-- Check the first categoryifcategorythenlocalcat=rawget(self, category)
element=catandcat[symbol]
-- Methods and enums are sypposed to be static, element can be nil-- but it is a NOP, so the "if" would be more expensiverawset(self, symbol, element)
elselocalcategories=self._categoriesor {}
-- Check all available categories.fori=1, #categoriesdocategory=categories[i]
localcat=rawget(self, category)
element=catandcat[symbol]
ifelementand (category=="_method" orcategory=="_enum" orcategory=="_union")thencached_symbol[1] =categorybreakendifelementthenbreakendendendendifelementthen-- Make sure that table-based attributes have symbol name, so-- that potential errors contain the name of referenced-- attribute.iftype(element) =='table' andcategory=='_attribute' thenelement._name=element._nameorsymbolendreturnelement, categoryendend
Avoid calling match as often, expressions/patterns are slow
Cache the category and name
rawset The methods and enums as (I don't think?) they will ever change
Remove the type() check. Let it crash and fix the bug where it is rather than mitigate the consequence.
Removed the check for "function" and "local". Why is it there?
Those changes change lua-callgrind benchmark from 16M to 10M total instruction cost for my Awesome WM config. callgrind.zip
I attach the profile with the fixes. I can be used with most valgrind compatible tools such as KCacheGrind
I tried caching everything using rawset, but attributes and structs will assert LGI with "got userdata, expected record". Any idea to cache even more?
The text was updated successfully, but these errors were encountered:
component.mt:_element
is called hundreds of thousand of time per minute. It is where the Awesome spend ~50% of its time (LGI account for up to 97% of the Lua time). Speed has gotten better since 0.6, but it is still not enough. Here is some proposed changes. I would also have idea how to better reduce the numbers of calls (this only make them less expensive).Here are some proposed changes and questions:
match
as often, expressions/patterns are slowrawset
Themethod
s andenum
s as (I don't think?) they will ever changetype()
check. Let it crash and fix the bug where it is rather than mitigate the consequence.Those changes change lua-callgrind benchmark from 16M to 10M total instruction cost for my Awesome WM config.
callgrind.zip
I attach the profile with the fixes. I can be used with most valgrind compatible tools such as
KCacheGrind
I tried caching everything using
rawset
, but attributes and structs will assert LGI with "got userdata, expected record". Any idea to cache even more?The text was updated successfully, but these errors were encountered: