Profile Treeform's Blog

A Network Adventure

May 28, 2015

This week I rewrote a large swath of Istrolid network code. Oh boy was it long overdue! The network was taking way too much CPU to compute. Originally I just copied the whole simulation state and performed a diff with the previous simulation state and sent the diff out to the clients. At the time I just wanted to play the game and not get stuck with stupid network logic. It was fast to write, it was easy, it was not efficient. Now I just do it with less copying objects around. I also reuse a lot more objects to appease the Javascript GC God. Have mercy on me and don't eat my FPS or produce frame jitter.

Also someone on IRC came around and looked at the performance profile for my game in Chrome tools and found my deepCopy function was taking like 60% of their CPU. I was embarrassed so I set out to optimize it. It runs much, much better now. My next step is to convert it to a binary protocol and make the clients predict more... but this will be built on top of this system rather than the old copy/diff the whole state. Now the CPU time is spent in copying webGL buffers around, a much better use of CPU time.