Off-Campus Apartment Creates Tremendous Lag
Myself (and others) have experienced an extremely high amount of lag when hosting multiple resources on Off-Campus Apartment. I found it happening after the number of hosted connections reached 4+, and the lag manifested itself in the form of server-response delay in clicking buttons and typing into chat (delay between 5 and 20 seconds).
Interestingly, it ONLY seemed to effect me (the runner): the corp reported experiencing no delays, and their turn seemed to proceed smoothly. Lag returns as soon as next runner's turn begins.
This may be a more general issue with card hosting? I have not experienced this issue with Personal Workshop or The Supplier, but it is admittedly unusual for either of those cards to have more than 3 cards hosted on them.
I have just started experiencing this on Personal Workshop. It's a new bug for me-- possibly created when hosting facedown was implemented? And it's really annoying haha.
It also happens with Leprechaun, particularly with nested Leprechauns.
I've noticed it with Off-Campus Apartment and Personal Workshop too. The lag increases dramatically with the number of hosted cards.
This deserves higher status than "dev." Scheherazade, Personal Workshop, and Off-Campus Apartment are mainstays of major runner strategies, so this bug renders the game all but unplayable for many shapers and some anarchs. And unlike most of the other outstanding bugs, there's no manual fix.
I'm diagnosing by behavior rather than code, but I think I can make a fair guess at what the problem is:
-
There's a loop in the representation of the host and hosted cards.
Maybe each hosted card contains a non-shallow reference to the host card, which references each hosted card, etc. The recursion obviously not infinite, but even two layers of references would make serializing the state of a Personal Workshop a task of order N^3.
This would account for why the "lag" is unnoticeable with 1 hosted card, bad with 3, and intolerable with 4+ (think 1, 8, 27, 64, 125, etc.). It would also explain why CPU usage increases and why not all users experience the problem to the same degree. The "lag" isn't on the server side at all... it's the additional work the loop demands of the user's CPU.
-
The full game state is being generated and/or passed to the server with every user action.
This would explain why a 4+ Personal Workshop causes every action to be delayed, rather than just PW-related actions.
This is indeed a serious issue. Some friends also reported their games become unplayable after hosting several cards.
I did some investigations on the live server and on my dev machine. The slowdown on my machine appears only after hosting 10+ cards on Personal Workshop. As more cards are hosted the slowdown is getting worse.
The CPU usage goes very high for several seconds on the Node process and when the game state is sent back to the clients (Chrome and Firefox) both browser processes get a very high CPU usage for several seconds. The game engine Java process never get a high CPU usage. This seems to indicate a performance issue appears when converting the game state from Clojure data structure to JSON (done by Node) and from JSON to Clojurescript data structure (done by the browsers).
@aiannacc is basicallly right about this.
When you install PW, you have something like
[:runner [:rig [:resources {:title "Personal Workshop"} ] ] ]
in your gamestate (note that card definitions are way bigger than just the single :title field). Once you host a card, it looks like
[:runner [:rig [:resources {:title "Personal Workshop" :hosted [ {:title "Cache" :host {:title "Personal Workshop" } } ] } ] ] ]
When you host a second card, this part of the game state looks like this
[:runner [:rig [:resources {:title "Personal Workshop" :hosted [ {:title "Cache" :host {:title "Personal Workshop" } } {:title "Corroder" :host {:title "Personal Workshop" :hosted [ {:title "Cache" :host {:title "Personal Workshop" } } ] } } ] } ] ] ]
So whenever you host a new card on PW, the entire PW card data inclusive all hosted cards is copied and added as :host to the hosted card.
Maybe we should just store the :cid of the host in the :host field of the hosted card? Then whenever a card needs its host, it should call a function like get-card first (which has to be implemented first).
I submitted a fix in #558. @queueseven nailed it: when hosting a new card, a copy of the current PW was being placed in its :host field, and that included all cards currently :hosted on PW.