Replies: 11 comments
-
Why would there be a catch? |
Beta Was this translation helpful? Give feedback.
-
Meant to say what's the reason behind this |
Beta Was this translation helpful? Give feedback.
-
It's the same question just worded differently ;) Pub/sub is faster because it's designed to be faster for Pub/sub. It's a misconception that it would be the same as a for loop. Shitty libraries implement it as just a for loop. But you probably want to benchmark end to end. |
Beta Was this translation helpful? Give feedback.
-
The websocket benchmark of https://bun.sh uses Pub/sub thats why it performs way better |
Beta Was this translation helpful? Give feedback.
-
Interesting, does pub/sub use .send under the hood? And if so, would it be possible for me to design a similar architecture but with a custom message for each client? |
Beta Was this translation helpful? Give feedback.
-
Typically these "IO games" send the same message to everyone but the sender, for every client. |
Beta Was this translation helpful? Give feedback.
-
Depends on the game. Some games send only entities that are within a certain distance from each player |
Beta Was this translation helpful? Give feedback.
-
It's the same. You just divide the game world into squares and have those be their own topic. Still overall same idea |
Beta Was this translation helpful? Give feedback.
-
Oh that's clever, never thought of splitting world just for sending messages. I always thought of it as a way to reduce collision checks |
Beta Was this translation helpful? Give feedback.
-
Is there a limit to how many topics I could create? I am planning having a 21x21 grid which is around 400 topics |
Beta Was this translation helpful? Give feedback.
-
You can have many many topics but always good to benchmark |
Beta Was this translation helpful? Give feedback.
-
I am currently working on a game, and I am sending the info of all 100 players to each other.
The way I am currently doing this is by doing
I benchmarked this loop and found that it takes around 12ms.
But when I switched to this
It only took around 3ms
So what's the catch here?
Beta Was this translation helpful? Give feedback.
All reactions