On 20/02/13 15:07, Victor Vasiliev wrote:
On 02/19/2013 06:21 PM, Tim Starling wrote:
The Wiktionary folk are gnashing their teeth today when they discovered that in fact, loading a 742KB module 1200 times in a single page does in fact take a long time, and it trips the CPU limit after about 450 invocations . So, sorry for raising expectations about that.
-- Tim Starling
Aren't modules which are already loaded cached, so if they load it 1200 times on a single page, how does it manage to affect CPU time that badly?
Execution of the module chunk seems to be the main reason. I benchmarked it locally at 10.6ms, so 450 of those would be 4.8s.
Lua has a lot of O(N) work to do when a large table literal is executed. I'm experimenting with using large string literals instead:
https://en.wiktionary.org/w/index.php?title=Module:Languages_string_db&action=edit
That module takes about 2us for module chunk execution, when I run it locally, and around 30us for each lookup in a tight loop on the server side. But when I use it in a large article, it seems to use about 1.4ms per #invoke, so maybe there's still some overhead that needs to be tracked down.
The idea of storing a database in a large string literal could be made to be fairly efficient and user-friendly if a helper module was written to do parsing and a binary search.
-- Tim Starling