Extension talk:VariablesLua

Jump to navigation Jump to search

About this board

Cavila (talkcontribs)

Interesting extension that I'd love to try out. I was wondering: why exactly did you develop this extension? Did you develop it to get better performance out of the Variables extension? Or does the Variables extension offer functionality that you can't get (easily) from Lua otherwise?

Litzsch (talkcontribs)

No it does not provide any additional functionality. All the extension does is call something like mw.getCurrentFrame():callParserFunction( '#var', 'foo' ) You can implement it with a module without much of a performance decrease. I think the main point of the extension is that it's easy to distribute across the Liquipedia wiki farm. The performance benefits are minimal at best.

local start = os.clock()
local var = mw.ext.VariablesLua.var
for i=1,10000 do
  var( 'foo' )
end
mw.log( os.clock() - start ) --> 0.114381835

local start = os.clock()
for i=1,10000 do
  mw.getCurrentFrame():callParserFunction( '#var', 'foo' )
end
mw.log( os.clock() - start ) --> 0.120059905

EDIT:

Seems like there's a bit more difference when also using <code>vardefine</code> (but probably still negligible):

local start = os.clock()
local var = mw.ext.VariablesLua.var
local vardefine = mw.ext.VariablesLua.vardefine
for i=1,10000 do
  vardefine( 'foo', 'bar' )
  var( 'foo' )
end
mw.log( os.clock() - start ) --> 0.151331927

local start = os.clock()
for i=1,10000 do
  mw.getCurrentFrame():callParserFunction( '#vardefine', { 'foo', 'bar' } )
  mw.getCurrentFrame():callParserFunction( '#var', 'foo' )
end
mw.log( os.clock() - start ) --> 0.253298621
Cavila (talkcontribs)

Thanks! I'm not aware of any performance issues with the Variables extension myself, but I was wondering if power users - people who aren't afraid to declare 500 variables on a single page - might stand to benefit from a Lua solution. Looks useful anyway.

FO-nTTaX (talkcontribs)

I know I'm late, but to jump in as the author: I mostly made this to familiarize myself with the interface of creating Scribunto extensions. Having an actual project that produces something is always more fun.

Reply to "Question"
There are no older topics