C
C#17mo ago
Co³

❔ Better way to check 2 dictionaries against one another?

I'm trying to write some logic for a game in Unity; a system that will check what items have been sent to the player before, and which have not (to prevent resending the same item, wasting network bandwidth). PlayerEntityHistory will be sent to a network function later. My code is currently "simulating" 200 players by populating a list with random player names. The code below is then called by just looping through each player and sending its name to the function. Issue is, with only 1000 entries in StreetSweeperResults (a measly 10 items per player), the fps of the editor craters to only 10fps from over 150 when there are no items. I'm running a decent rig (Ryzen 5 5600) and I'm really surprised at how slowly it's working. Is there a way I could speed this up? I feel like there's some solution and I'm just not seeing it, and I know it has to do with me using this nested FOR loop. I've tried things like TryGetValue instead of ContainsKey for the dict lookups but this had minimal impact, and I'm not sure how else to get this same logic without that nested loop. Thanks in advance for any thoughts :)
2 Replies
Co³
Co³OP17mo ago
Think I thought of something. Found the System.Linq intersect method. I’ll try that tomorrow afternoon and see if that’s faster.
Accord
Accord17mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server