RosaryMala / armok-vision

A 3d realtime visualizer for Dwarf Fortress
MIT License
320 stars 27 forks source link

High memory usage with low responsiveness #53

Open alexchandel opened 7 years ago

alexchandel commented 7 years ago

Armok Vision uses over 7 GB of memory after enabling FPS mode and walking around a small map.

This seems excessive, considering barely any of the world is rendered except a few layers. Contrast this with tile-based games like Minecraft which render similar numbers of tiles using much less memory and with more responsiveness.

RosaryMala commented 7 years ago

Blame it on my inexperience.

I'll see what I can do to trim things down a bit.

RosaryMala commented 7 years ago

Could you give a copy of your save, so I can test it?

alexchandel commented 7 years ago

There's just room for optimization, and I think even small optimizations will yield noticeable gains in performance.

~And sure, how should I transmit it? Do you have an FTP site? It's 37M when compressed as a tar.xz.~ Here's the save

alexchandel commented 7 years ago

Notably, loading it and entering FPS mode, without walking around or anything, Armok Vision is already using 4GB+ and 100% CPU, and it doesn't seem like it's laid out all the layers yet, since I see the tops of trees appearing occasionally. Eventually it falls to 60% CPU, but as soon as I begin walking around, or worse descending staircases, it uses 175%+ CPU and the memory usage shoots up. The game is paused in all cases.

Also, dwarfort.exe is using 40-50% CPU now, up from 5-7% before AV started. Could the polling performed by AV be throttled, or halted/dramatically slowed when the game is paused, or restricted to only visible areas?

alexchandel commented 7 years ago

Were you able to download the save?

RosaryMala commented 7 years ago

I've been out of town for two days.

alexchandel commented 7 years ago

Ok. I can reupload the save if the download link expires.

alexchandel commented 7 years ago

Here's a reupload if necessary.

alexchandel commented 6 years ago

Tested with v0.18.0. Memory usage now seems lower, but is still north of 3 GB. And CPU usage is now ~35% instead of 200%, except when walking around in FPS mode (at least when the game is paused, which is all I've checked)

However, the game view is still very slow. I barely get 1 frame/s when walking in FPS when the game in paused, despite using the "Fastest" setting with only 1680x1050 resolution.

Could this be related to the huge number of threads Armok Vision spawns? I've seen it get as high as 44 threads, again while the game was paused. This seems excessive.

RosaryMala commented 6 years ago

Armok Vision itself only spawns 6 threads by default, the main thread, 1 thread for communicating with Df, and 4 mesh regeneration threads. All the rest are made by Unity for its own purposes.

alexchandel commented 6 years ago

The thread count slowly increases over time. Is it possible Unity is leaking threads? Or that AV is leaking some Unity resource that causes it to spawn more threads over time?

alexchandel commented 6 years ago

Given that a 3x3 embark of 48x48 tiles each corresponds to a 9x9 chunk Minecraft area, and I can easily render that well above 60 fps, the sluggishness isn't intrinsic the complexity of rendering or meshing a voxel grid of this size. It should be possible to have far better performance.