Repository navigation
Closed
Labels
Description
Summary
The speedometer-hud example is presented as the model for "rate-limited SendNUIMessage", but its condition uses or, so it sends on every frame while the speed changes and also every 100 ms when the speed is unchanged.
Where
examples/speedometer-hud/client/main.lua:43-51examples/speedometer-hud/fxmanifest.lua:6(description: "rate-limited SendNUIMessage")
Details
-- Rate-limit: only push a 'speed' message when the displayed integer
-- changes, or at most once every 100ms to keep the readout fresh.
if speed ~= lastSpeed or (now - lastSent) >= 100 then
lastSpeed = speed
lastSent = now
SendNUIMessage({ action = 'speed', value = speed, unit = Config.Unit })
end
Wait(0)- While accelerating or braking, the integer speed changes almost every frame, so the
speed ~= lastSpeedbranch sends 60+ messages per second with no limit. - At a steady speed, the
orbranch still sends about 10 identical messages per second, which do nothing in the UI (it only setstextContent). - The loop runs at
Wait(0)with three natives per frame, although a speed readout does not need per-frame updates.
Impact
The cost per message is small, so runtime impact is low, but the example teaches the opposite of what it claims, and users copying it into heavier HUDs inherit the extra NUI traffic.
Steps to reproduce
- Add a counter around line 48 and print it once per second.
- Accelerate in a vehicle: the count tracks the frame rate. Hold a constant speed: about 10 identical sends per second.
Suggested fix
- Send only when
speed ~= lastSpeedand at least N ms have passed since the last send (and, notor); drop the unconditional 10 Hz refresh. - Use
Wait(50)orWait(100)while in a vehicle instead ofWait(0). - Make the comment and README match the code.
Acceptance criteria
- At most one
speedmessage per configured interval while driving, and none while the displayed value is unchanged. - Comment, README and manifest description describe the actual behaviour.
Getting started
- Relevant files:
examples/speedometer-hud/client/main.lua,examples/speedometer-hud/README.md - How to run checks: there is no test suite yet; run the MCP server with
cd mcp-server && pip install -r requirements.txt && python server.py, and CI checks live in.github/workflows/validate.yml - Related docs:
skills/nui-development/SKILL.md,skills/performance-optimization/SKILL.md
Filed by repo-audit/full-audit at 701824d. Severity: low. Effort: S. audit-key: performance|examples/speedometer-hud/client/main.lua|SendNUIMessage
Activity
TMHSDigital commentedon Nov 21, 2026
Fixed in 8286f75.
The HUD now polls every 100ms while driving and sends a
speedmessage only when the displayed value changed and the interval passed (at most about 10 per second, none while steady); comments and README describe that.Verified: Reviewed the loop logic against the acceptance criteria (no FXServer available here to measure).