Need help with hud performance

i have developed a custom HUD for my project, and I encountered an issue related to the weapon data section. Whenever a weapon is equipped, there is a noticeable increase in milliseconds (ms) from 0.00 to 0.17, causing performance concerns. I am seeking guidance on how to address and rectify this performance degradation, ensuring a seamless and smooth experience for users. Any insights or recommendations to resolve this matter would be greatly appreciated.

local isHUDVisible = false

function HUD:UpdateUI()
    while true do
        local sleep = 3000  
        local isWeapon, weaponHash = GetCurrentPedWeapon(PlayerPedId(), true)

        if isWeapon then
            local weaponName = TXGetWeaponName(weaponHash)
            local clipSize = GetAmmoInPedWeapon(PlayerPedId(), weaponHash)
            local _, ammo = GetAmmoInClip(PlayerPedId(), weaponHash)

            SendNUIMessage({
                action = "weaponInfo",
                ammo = ammo,
                clipSize = clipSize - ammo,
                weaponName = weaponName
            })

            isHUDVisible = true
            sleep = 300
        else
            if isHUDVisible then
                SendNUIMessage({ action = "hideWeaponInfo" })
                isHUDVisible = false
            end
        end

        Citizen.Wait(sleep)
    end
end

Citizen.CreateThread(function()
    while not ESX.PlayerLoaded do
        Citizen.Wait(200)
    end

    HUD:UpdateUI()
end)

Store the value of PlayerPedId() and reuse it, also consider increasing the sleep from 300 to something like 500 or even 1000. Otherwise that’s as good as it’s going to get.

thank you