[TM FIRST] Literally just halves the performance cost of cameras (#94522)

## About The Pull Request

Title, I used an alist and some inlined list operation tricks to make
camera chunk updates twice as fast.

The data in the screenshots is from me updating every single camera
chunk on Meta. I did also test on Icebox and it scaled just as well
there as it did on Meta, which means that multi-z doesn't cause any
issues for these changes.

The correct way to compare these costs is to take the total cost, divide
it by the count, and then compare them relatively to see which is
higher/lower and by how much.

Before:
<img width="415" height="306" alt="image"
src="https://github.com/user-attachments/assets/c3be5986-e405-412d-a9e0-cc34014a7dab"
/>

After (combined keys):
The value of "update visible turfs" here is just a merged version of
"collect turfs" + "the & operator" + "update visible turfs"
<img width="356" height="271" alt="image"
src="https://github.com/user-attachments/assets/93ca0e9a-bf17-4b87-a4f0-c70c70148ab0"
/>

After 2 (separate keys, but fucked up counts):
Not as directly comparable cuz the counts are fucked up, gotta do some
math to figure it out.
<img width="414" height="293" alt="image"
src="https://github.com/user-attachments/assets/205d4842-4294-4130-a7dd-69d196d318e9"
/>

The biggest remaining performance bottleneck, which now accounts for
~70% of all the performance cost of camera chunks, is camera.can_see()
being slow as balls. You can see this in the After 2 image.

The only cost of doing this is that the format of the list is now
"alist[turf] = null" instead of "list[i] = turf", which makes checking
for individual turfs cumbersome. Entirely possible and and still
relatively performant, but the syntax is just cumbersome. Said single
checks are only used by SyndEye as of now.
## Why It's Good For The Game

On live, it seems that camera chunks are consistently the biggest and
fattest source of performance loss and overtime in the entire game.
Obviously halving that cost is good for the game.
## Changelog
🆑
fix: Camera chunks, the biggest source of lag in the entire game, now
run twice as fast.
/🆑
This commit is contained in:
RikuTheKiller
2026-01-17 00:18:41 +02:00
committed by GitHub
parent c6c900b1fe
commit 8f98047bfe
3 changed files with 15 additions and 9 deletions
@@ -174,7 +174,7 @@
CRASH("[src] was able to track [target] through /datum/trackable, but was not on a visible turf to cameras.")
for(var/obj/machinery/camera/cameras as anything in target_camerachunk.cameras[target.z])
// We need to find a particular camera that can see this turf
if(!(target_turf in cameras.can_see()))
if(length(cameras.can_see() & list(target_turf)))
continue
var/new_camera = WEAKREF(cameras)
if(camera_ref == new_camera)