Use BlockingCollection instead of ConcurrentQueue in ArchipelagoSocketHelper_system.net.websockets.cs to fix high cpu usage due to continuosly polling for packets to send.
This was tested on a toy implementation and it seems to work just fine, it would be appreciated if someone tried this in an actual session though.
This is how much cpu a sample console app that just connects uses.
without pr:
with pr:
There's one thing I noticed with this change, if multiple packets are continuously added with SendMultiplePacketsAsync very fast they may get sent within a single message to the socket instead of multiple, since more packets are added asynchronously to sendQueue while the while loop is already running and adding packets to packetList. I don't think this has any adverse effect though.
Also, the check to see if packetList is empty shouldn't be needed anymore (since the method blocks on sendQueue.Take() if senQueue is empty), but I wasn't sure so I kept it.
Use
BlockingCollection
instead ofConcurrentQueue
inArchipelagoSocketHelper_system.net.websockets.cs
to fix high cpu usage due to continuosly polling for packets to send.This was tested on a toy implementation and it seems to work just fine, it would be appreciated if someone tried this in an actual session though.
This is how much cpu a sample console app that just connects uses. without pr: with pr:
There's one thing I noticed with this change, if multiple packets are continuously added with
SendMultiplePacketsAsync
very fast they may get sent within a single message to the socket instead of multiple, since more packets are added asynchronously tosendQueue
while thewhile
loop is already running and adding packets topacketList
. I don't think this has any adverse effect though.Also, the check to see if
packetList
is empty shouldn't be needed anymore (since the method blocks onsendQueue.Take()
ifsenQueue
is empty), but I wasn't sure so I kept it.