The hash-operator for tables in Lua is often implemented as a counting operation, not a kept state. In later versions it is a metamethod, and it may or may not be counting. If it is implemented as a counting operation, then if it used inside loops it will give rise to O(N²) complexity.
Related Gerrit Patches:
|mediawiki/extensions/Wikibase : master||Wikibase: Avoid recounting of entries in getBestStatements|