Skip to content

perf: lazy load MGUMatch/MGUGame fields#7610

Open
ElectricalBoy wants to merge 8 commits into
mainfrom
standings-match2-perf
Open

perf: lazy load MGUMatch/MGUGame fields#7610
ElectricalBoy wants to merge 8 commits into
mainfrom
standings-match2-perf

Conversation

@ElectricalBoy
Copy link
Copy Markdown
Collaborator

@ElectricalBoy ElectricalBoy commented Jun 5, 2026

Summary

See #7398 for context.
Some fields in MGUMatch/MGUGame are not used in certain contexts, e.g., a lot of extradata fields in MGUGame are not needed during match results processings in standings tables. This PR adds lazy loading to such fields to reduce overall memory consumption.

How did you test this change?

https://liquipedia.net/valorant/User:ElectricalBoy/Sandbox2

Live PR
Runtime 0.751 s 0.716 s
Memory 41.48 MB 36.38 MB

Copy link
Copy Markdown
Collaborator

@mbergen mbergen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test how this affects MatchTable? IIRC that's also using this.

Comment thread lua/wikis/commons/Standings/Parse/Lpdb.lua
@ElectricalBoy ElectricalBoy added the c: match_table Match Table for on /Matches pages or "Recent Matches" sections label Jun 5, 2026
@ElectricalBoy
Copy link
Copy Markdown
Collaborator Author

Can you test how this affects MatchTable? IIRC that's also using this.

4508f5e

@Rathoz
Copy link
Copy Markdown
Collaborator

Rathoz commented Jun 5, 2026

While I like the approach, since so many m2g will need to be loaded, it may be worth batching them rather than going back and forth with the database. While the Lua time difference is negligible, the real-time difference can add up. Also, we need to look at not loading the m2g extradata field to reduce memory further

@ElectricalBoy
Copy link
Copy Markdown
Collaborator Author

ElectricalBoy commented Jun 5, 2026

While I like the approach, since so many m2g will need to be loaded, it may be worth batching them rather than going back and forth with the database.

because lazy loading is implemented through __index metamethod, it will not do any additional query if match2.match2games field is already populated, i.e., if the consumer knows that it will need m2g then they could preload them by simply adding match2games to lpdb query param
so this pr is specifically for those that we expect to not require m2g

Also, we need to look at not loading the m2g extradata field to reduce memory further

that part is already included

---@param matchId string
---@return match2game[]
function MatchRecordMT._fetchGames(matchId)
local gameRecords = mw.ext.LiquipediaDB.lpdb('match2game', {
conditions = '[[match2id::' .. matchId .. ']]',
query = 'date, game, length, map, mode, opponents, patch, resulttype, status, scores,' ..
'subgroup, type, vod, walkover, winner',
order = 'match2gameid asc',
limit = 1000,
})
Array.forEach(gameRecords, function (gameRecord, index)
setmetatable(gameRecord, {
__index = function (t, k)
if k == 'extradata' then
local queriedExtradata = mw.ext.LiquipediaDB.lpdb('match2game', {
conditions = '[[match2id::' .. matchId .. ']] AND [[match2gameid::' .. index .. ']]',
query = 'extradata',
limit = 1,
})[1].extradata
t.extradata = queriedExtradata
return queriedExtradata
end
end
})
end)
return gameRecords
end

@ElectricalBoy ElectricalBoy force-pushed the standings-match2-perf branch from 9d24c8a to 5decb63 Compare June 8, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: match_table Match Table for on /Matches pages or "Recent Matches" sections c: match2 c: standings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants