65th Beam Update Slow

Beam Lag Repro.rbxl (18.4 KB)
Setting the CurveSize0 of the 65th Beam.

Problem:
If you update 64 beams per frame, it is fast and takes 0.1ms
If you update 65 beams per frame, it takes significantly longer.
The longer you run it for, the slower updating the 65th beam is.
This also applies to trails

Repro:

  1. Generate some beams
  2. Within a frame, update more than 64 of those beams

What my output reads:

--[[
      TEST RESULTS:
          num beam updates: 64
          update time (ms): 0.1
      TEST RESULTS:
          num beam updates: 65
          update time (ms): 23.2
]]
--Put this in a LocalScript in game.StarterPlayer.StarterPlayerScripts

local beams = {}
for i = 1, 100 do
    table.insert(beams, Instance.new("Beam", workspace))
end

local frameCount = 0
game:GetService("RunService").Stepped:connect(function()
    local updateNumber
    if frameCount == 0 then
        updateNumber = 64
    else
        updateNumber = 65
    end
    frameCount = (frameCount + 1)%2

    local t0 = tick()
    for i = 1, updateNumber do
        --UPDATE THE BEAM IN SOME WAY
        beams[i].CurveSize0 = math.random()
    end
    local t1 = tick()
    print(string.format("TEST RESULTS:\n    num beam updates: %d\n    update time (ms): %2.1f", updateNumber, 1000*(t1 - t0)))
end)
2 Likes

I’ve been having this issue as well. Even when ending a play test in studio, and starting another test, it still has lag. The only way I’ve found to temporarily reduce it again is by restarting studio entirely.

Also I’d like to point out that after the 65th beam, there is no longer an issue. Not sure if this applies to the 129th beam tho.

1 Like

Hmm I think this is a separate problem from the one I am describing. You should consider making a separate post about your issue. OH AND WELCOME!

I think my post is not clear enough.

If a script makes changes to 65 or more Beam instances in a RunService loop, it has large performance implications. This is not so if the script makes changes to 64 or fewer Beam instances in a RunService loop.

Your post was clear, I accidentally typed “frame” instead of “beam”, my bad. I’m updating the texture speed of about 70 beams and on the 65th I have the same issue you described.

Oh I see, yeah it does not apply to the 129th! Only to the 65th.

I second this, I got numbers varying from 0.9 to 2.6
image

It’s not quite 23 ms but it’s definitely an interesting jump up.

edit: ran it for longer and it started to climb up, as OP said. I didn’t notice that at first. Seemed to stabilize around going up to taking 6 ms, going back down, and going back up.

Thanks for the report. Investigating now.

5 Likes

Any update? It’s been a month since this was originally posted.

It should have been fixed. Do you still have the problem?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.