matej_suchanek created this task.
matej_suchanek added projects: MediaWiki-extensions-WikibaseClient, Performance.
Herald added subscribers: PokestarFan, Aklapper.
Herald added a project: Wikidata.

TASK DESCRIPTION

Run this module (sorts a sequence of numbers by the label of the item with the same numeric id)

local p = {}

local function getLabel(id)
	return mw.wikibase.label(id) or ''
end

function p.test()
	local array = {}
	for i = 201, 400 do
		table.insert(array, i)
	end
	local start = os.clock()
	table.sort(array, function(a, b)
		return getLabel('Q' .. a) < getLabel('Q' .. b)
	end)
	local stop = os.clock()
	mw.log(stop - start)
end

return p

and check the result (should be around 1.5).

Now change getLabel to:

local cache = {}
local function getLabel(id)
	if not cache[id] then
		cache[id] = mw.wikibase.label(id) or ''
	end
	return cache[id]
end

and run again. The result should be around 0.1.

This significant difference means that repeated loading of the same label does not use (client-side) cache. (Other functions probably have the same problem.)


TASK DETAIL
https://phabricator.wikimedia.org/T173241

EMAIL PREFERENCES
https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: matej_suchanek
Cc: Aklapper, matej_suchanek, PokestarFan, GoranSMilovanovic, QZanden, Vali.matei, Volker_E, Izno, Wikidata-bugs, aude, GWicke, Mbch331, Jay8g
_______________________________________________
Wikidata-bugs mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikidata-bugs

Reply via email to