I am working on prototyping a video game. I have a function `state->pict` 
that takes a game state and creates a pict to be drawn on a canvas. When I 
`time` this function I get nice low numbers like "cpu time: 0 real time: 2 
gc time: 0"

The problem occurs when I am running a networked multiplayer game. The size 
and complexity of the state remains the same (a "state" represents only one 
player's state). But the mere presence of other threads doing network IO 
somehow slows down `state->pict` which is strange because it is a pure 
function. I get timing results like "cpu time: 78 real time: 71 gc time: 
0". If I stop the network activity mid-game, after a few seconds it will 
start running quickly again.

This makes me think that other threads are interrupting state->pict and 
that this interruption is being captured by `time`. Is that plausible?

Do I need to use a separate place for the network request/response queue? 
Right now, I am just using `thread` like this:

    ; (-> request (evtof response))
    (define/public (sendrq rq)
      (let ([result (box #f)])
        (wrap-evt (thread (lambda () (set-box! result (send/recv rq))))
                  (lambda args (unbox result)))))

There is one other area that concerns me: I am using `read` on the 
input-port returned by `tcp-connect`. I was hoping that `read` would yield 
while it is waiting for the datum to arrive on the port, but maybe it spins 
instead which would explain the elevated CPU usage.

I tried `raco profile my-game.rkt` but that only profiles the time it takes 
to show the initial frame. Is there some other technique I can use to 
profile the game while it is running?

Thanks in advance for any suggestions.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/87d2b914-2b9e-4d27-9ea9-739df42adb36n%40googlegroups.com.

Reply via email to