Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading a level client-side is CPU-intensive server-side #80

Open
ramnes opened this issue Aug 18, 2022 · 4 comments
Open

Loading a level client-side is CPU-intensive server-side #80

ramnes opened this issue Aug 18, 2022 · 4 comments
Labels
enhancement New feature or request up-for-grabs

Comments

@ramnes
Copy link
Contributor

ramnes commented Aug 18, 2022

We are seeing some levels that take something like 20+ seconds to load on a 2021 M1 MacBook Air (Chrome).

It doesn't happen on empty levels. It seems that the more tiles a level has, the longer it takes to load, which makes sense. What I don't explain is why it takes so much time to load on our instance when other levels with as many tiles on app.lemverse.com seem to load very fast.

The issue seems to be on the client side (all HTTP requests complete quite quickly); but that's weird because then it doesn't make sense that the loading time depends on the instance it's connected to.

We have planned to investigate the issue, so don't feel obligated to spend time on this, but any clues would be appreciated!

@Donorhan
Copy link
Contributor

I've been looking for solutions to this problem quite a bit. The problem comes mainly from the Tiles collection.

Each cell is a Tile document, a level has by default 8 layers and per layer 100x100 cells. This makes a maximum synchronization of 80000 documents to load, even if a level of 100x100 has on average 16000 documents, it is already huge.

The solutions I have in mind:

Change the structure of a level

We should delete the Tiles collection and have the following syntax on the level:

{
  "_id": "lvl_x",
  "layers": [
    { tiles: [0, 100000, 60000, ... ] }
    { tiles: [5, 4, 8747, ... ] }
    { tiles: [2, 20, 2535, ... ] }
    { tiles: [3, 2399, 84682, ... ] }
  ]
}

The problem with this solution is that we lose the reactivity of Meteor when editing the level but the loading time will be much less important and the server will not have to monitor the X document of the tiles

Generate the level server side

The idea would be to have the whole map static (except the entities). Images would be generated on the server side.

  • A layer under the character
  • A layer above the character

Each level would be split in chunks, it's the same way Google Maps works.

Advantages:

  • Instant loading of the level
  • Less textures on the client side (no need to load all tilesets) and the generated images will be ~100kb max
  • Less greedy rendering for the client: a few images to display rather than several GPU calls
  • The culling pass will not have to go through the whole tilemap to know what is on the screen, this is the most greedy part on the client side currently

Disadvantages :

  • Loss of responsiveness when editing

@ste-mae
Copy link

ste-mae commented Aug 18, 2022 via email

@Donorhan Donorhan added the enhancement New feature or request label Aug 30, 2022
@ramnes
Copy link
Contributor Author

ramnes commented Aug 31, 2022

We found a workaround by giving more CPU to lemverse, which appeared to be the bottleneck here. It seems that a user loading a level is very CPU-intensive for lemverse on the server-side, and that's the real issue to fix.

@ramnes ramnes changed the title Levels can take a long time to load Loading a level client-side is CPU-intensive server-side Aug 31, 2022
@Donorhan
Copy link
Contributor

Donorhan commented Sep 1, 2022

It's probably related to tile synchronization which requires a constant link between the client and the server 😢. I think that removing the subscribe to tiles and managing the edition with simple events out of observe Meteor would fix the problem for both client and server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request up-for-grabs
Projects
None yet
Development

No branches or pull requests

4 participants