cyberbotics / webots

Webots Robot Simulator
https://cyberbotics.com
Apache License 2.0
3.24k stars 1.7k forks source link

`village_center.wbt` needs some optimizations #3296

Open ad-daniel opened 3 years ago

ad-daniel commented 3 years ago

Describe the Bug World village_center.wbt needs some optimizations. During the loading it goes through the processes:

  1. Parsing Nodes
  2. Downloading assets
  3. Finalize nodes
  4. Finalize nodes

During step (3), the memory consumption skyrockets to 12 GB (100%). Also, by reloading a few times, it doesn't always appear that step (2) gets consistently faster after caching. Some reloads appear to take as long as the first time.

On two occasions, after reloading a few times (and losing focus with the window while it was loading (not sure this is necessary for it to happen)), the Windows UI ended up crashing. Likely because of the memory usage.

I suspect a specific object might be the culprit as other big worlds don't suffer nearly as much.

This doesn't appear to be a regression however, the memory usage was already huge on master.

lukicdarkoo commented 3 years ago

it doesn't always appear that step (2) gets consistently faster after caching. Some reloads appear to take as long as the first time.

I assume it is because of many HTTP requests that are checking whether the files have changed online. This should never happen in our case, so I would disable this feature in the QT cache (if possible).

omichel commented 3 years ago

I would disable this feature in the QT cache (if possible).

This is indeed possible, but if a user changes the resource online, Webots will not use it and it will use the old one from its cache, which may not be desirable. Maybe we could add a preference item in the cache section called "cache policy" that would provide two options, like "prefer cache, prefer network" and would default to "prefer cache" to optimize performance, but could be turned to "prefer network" in case the online resources are changing.

lukicdarkoo commented 3 years ago

https://github.com/cyberbotics/webots/blob/2f78ab4c83ba4e71b578a4435b4cf45b245b6153/src/webots/nodes/utils/WbDownloader.cpp#L91-L92

I believe this should be replaced with:

request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);

Maybe we could add a preference item in the cache section called "cache policy" that would provide two options, like "prefer cache, prefer network" and would default to "prefer cache" to optimize performance, but could be turned to "prefer network" in case the online resources are changing.

Ideally yes, but for now they can use simple tricks to avoid the cache, like adding ?v=[version_number]: https://raw.githubusercontent.com/cyberbotics/webots/master/projects/default/worlds/textures/old_brick_wall.jpg?v=3

BenjaminDeleze commented 1 year ago

As found out in #5178, the church seems to be the problem (at least one of the proto that have issues) This seems to be due to the textures because changing all the geometries to simple boxes does not change anything.

We investigate a bit with @ygoumaz and so far:

We think it is an issue because the textures weight only a couple a MB and should be handle by the GPU.

BenjaminDeleze commented 1 year ago

We found the issue: the resolution. All the images of the church are 2048 x 2048. when loaded in Webots, qt uncompressed them because we need to have an array of pixels:

We use the QImage::Format_ARGB32 format. So the size of one image = 2048204832 = around 16MB We have 15 images for the Church.proto => 240MB of RAM!

We tested to reduce the resolution to 1024 x 1024 and the number matches: we dropped to 60MB of RAM.

So this is not a bug, but it is still annoying.

We see two possible solutions: