I either forgot or never learned that the profile functionality is 
available programmatically. And `create-sampler` can track a single thread 
which is exactly what I want (the UI thread). The profile results are 
surprising, but at least I have some ideas to try now.

On Sunday, April 4, 2021 at 12:55:32 PM UTC-5 Ryan Kramer wrote:

> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/58d34d1e-d2d2-445b-a1d6-40fb814e7e55n%40googlegroups.com.

Reply via email to