Moving-Castles / this-cursed-machine

Body horror fulfilment center simulator
MIT License
23 stars 3 forks source link

Bad client performance because of frequent entities store updates #264

Open pwrstudio opened 1 month ago

pwrstudio commented 1 month ago

Continuation of https://github.com/Moving-Castles/this-cursed-machine/issues/262

Problem

Client is laggy. The entities store is updated every time any table is updated.

Due to how the tables are structured, with CarriedBy, indicating which pod a machine belongs in, not being a key there does not seem to be a way for us to filter to only get the content of the players pod from the indexer.

The loading problem in https://github.com/Moving-Castles/this-cursed-machine/issues/262 was improved by not relying on the update streams to set the initial local state. Rather using this: https://github.com/Moving-Castles/this-cursed-machine/blob/main/packages/client/src/svelte/modules/systems/initEntities.ts

And then ignoring updates where the new and old values are the same: https://github.com/Moving-Castles/this-cursed-machine/blob/c64eed60170bae370356150e9ddeeba465b2f41f/packages/client/src/svelte/modules/systems/createComponentSystem.ts#L14

Problems are:

How do we ignore updates that are not relevant to the player?

The heavy part of the update is this: https://github.com/Moving-Castles/this-cursed-machine/blob/c64eed60170bae370356150e9ddeeba465b2f41f/packages/client/src/svelte/modules/systems/createComponentSystem.ts#L25

Solutions / improvements