Improve player system memory usage and performance#1216
Open
CaseIRL wants to merge 2 commits intoqbcore-framework:mainfrom
Open
Improve player system memory usage and performance#1216CaseIRL wants to merge 2 commits intoqbcore-framework:mainfrom
CaseIRL wants to merge 2 commits intoqbcore-framework:mainfrom
Conversation
Rewrites player.lua to use a class-based prototype pattern with shared methods via __index and weak-keyed private state to reduce memory usage and improve performance at scale. All existing scripts continue to work without any changes needed, QBCore.Functions.GetPlayer() acts as an API layer. Each GetPlayer call still creates closures for the proxy but these are short-lived rather than permanently stored on the player object still a net improvement over the original. - player.lua: Virtually a full rewrite to class methods - functions.lua: New helper added, all player lookups updated - events.lua: Internal player handling cleaned up
Title says it all. I forgot to swap the Player.Functions calls in paycheck interval to call class methods.
Author
|
I forgot to do the PaycheckInterval in this function PaycheckInterval()
if not next(QBCore.Players) then
SetTimeout(QBCore.Config.Money.PayCheckTimeOut * (60 * 1000), PaycheckInterval) -- Prevent paychecks from stopping forever once 0 players
return
end
for _, Player in pairs(QBCore.Players) do
if not Player then return end
local payment = QBShared.Jobs[Player.PlayerData.job.name]['grades'][tostring(Player.PlayerData.job.grade.level)].payment
if not payment then payment = Player.PlayerData.job.payment end
if Player.PlayerData.job and payment > 0 and (QBShared.Jobs[Player.PlayerData.job.name].offDutyPay or Player.PlayerData.job.onduty) then
if QBCore.Config.Money.PayCheckSociety then
local account = exports['qb-banking']:GetAccountBalance(Player.PlayerData.job.name)
if account ~= 0 then
if account < payment then
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('error.company_too_poor'), 'error')
else
Player:AddMoney('bank', payment, 'paycheck')
exports['qb-banking']:RemoveMoney(Player.PlayerData.job.name, payment, 'Employee Paycheck')
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
end
else
Player:AddMoney('bank', payment, 'paycheck')
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
end
else
Player:AddMoney('bank', payment, 'paycheck')
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
end
end
end
SetTimeout(QBCore.Config.Money.PayCheckTimeOut * (60 * 1000), PaycheckInterval)
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Rewrites player.lua to use a class-based prototype pattern with shared methods via __index and weak-keyed private state to reduce memory usage and improve performance at scale.
All existing scripts continue to work without any changes needed, QBCore.Functions.GetPlayer() acts as an API layer. Each GetPlayer call still creates closures for the proxy but these are short-lived rather than permanently stored on the player object still a net improvement over the original.
Mock Object Benchmark
32 players | Old: 87.99 KB | New: 43.43 KB | Saved: 44.56 KB
64 players | Old: 188.37 KB | New: 86.87 KB | Saved: 101.50 KB
128 players | Old: 376.77 KB | New: 173.77 KB | Saved: 203.00 KB
256 players | Old: 753.64 KB | New: 347.64 KB | Saved: 406.00 KB
512 players | Old: 1507.39 KB | New: 695.39 KB | Saved: 812.00 KB
1024 players | Old: 3014.92 KB | New: 1390.92 KB | Saved: 1624.00 KB
2048 players | Old: 6030.92 KB | New: 2782.92 KB | Saved: 3248.00 KB
Checklist