Optimize net server perfomance by substituting List by Data.Sequence for storing spectators data
--- a/netserver/HWProto.hs Mon Jan 12 14:55:30 2009 +0000
+++ b/netserver/HWProto.hs Mon Jan 12 14:57:42 2009 +0000
@@ -6,6 +6,8 @@
import IO
import Data.List
import Data.Word
+import Data.Sequence(Seq, (|>), empty)
+import Data.Foldable(toList)
import Miscutils
import Maybe
import qualified Data.Map as Map
@@ -245,7 +247,7 @@
[]
else
(answerClientOnly ["RUN_GAME"]) ++
- answerClientOnly ("GAMEMSG" : "DGUkc3BlY3RhdGUgMQ==" : roundMsgs clRoom)
+ answerClientOnly ("GAMEMSG" : "DGUkc3BlY3RhdGUgMQ==" : (toList $ roundMsgs clRoom))
handleCmd_noRoom client clients rooms ["JOIN", roomName] =
handleCmd_noRoom client clients rooms ["JOIN", roomName, ""]
@@ -368,7 +370,7 @@
handleCmd_inRoom client _ rooms ["START_GAME"] =
if isMaster client && (playersIn clRoom == readyPlayers clRoom) && (not $ gameinprogress clRoom) then
if enoughClans then
- (noChangeClients, modifyRoom clRoom{gameinprogress = True, roundMsgs = []}, answerRunGame)
+ (noChangeClients, modifyRoom clRoom{gameinprogress = True, roundMsgs = empty}, answerRunGame)
else
(noChangeClients, noChangeRooms, answerTooFewClans)
else
@@ -397,7 +399,7 @@
handleCmd_inRoom client clients rooms ["ROUNDFINISHED"] =
if isMaster client then
- (modifyRoomClients clRoom (\cl -> cl{isReady = False}), modifyRoom clRoom{gameinprogress = False, readyPlayers = 0, roundMsgs = []}, answerAllNotReady)
+ (modifyRoomClients clRoom (\cl -> cl{isReady = False}), modifyRoom clRoom{gameinprogress = False, readyPlayers = 0, roundMsgs = empty}, answerAllNotReady)
else
(noChangeClients, noChangeRooms, [])
where
@@ -411,7 +413,7 @@
addMsg = if roomProto clRoom < 20 then
noChangeRooms
else
- modifyRoom clRoom{roundMsgs = roundMsgs clRoom ++ [msg]}
+ modifyRoom clRoom{roundMsgs = roundMsgs clRoom |> msg}
clRoom = roomByName (room client) rooms
handleCmd_inRoom client clients rooms ["KICK", kickNick] =
--- a/netserver/Miscutils.hs Mon Jan 12 14:55:30 2009 +0000
+++ b/netserver/Miscutils.hs Mon Jan 12 14:57:42 2009 +0000
@@ -4,10 +4,11 @@
import Control.Concurrent.STM
import Data.Word
import Data.Char
-import Data.List
+import Data.List(find)
import Maybe (fromJust)
import qualified Data.Map as Map
import Data.Time
+import Data.Sequence(Seq, empty)
import Network
data ClientInfo =
@@ -59,7 +60,7 @@
readyPlayers :: Int,
isRestrictedJoins :: Bool,
isRestrictedTeams :: Bool,
- roundMsgs :: [String],
+ roundMsgs :: Seq String,
params :: Map.Map String [String]
}
createRoom = (
@@ -74,7 +75,7 @@
0
False
False
- []
+ Data.Sequence.empty
Map.empty
)