Mehni / kNumbers

Quick comparison of colonist stats
MIT License
34 stars 28 forks source link

Reordering columns performance issue #24

Closed dawnmist closed 4 years ago

dawnmist commented 4 years ago

I originally posted this issue here when they unofficially updated Numbers to version 1.1: https://github.com/ErwinM/kNumbers/issues/7

Firstly: Numbers is the first Mod I ever installed for Rimworld, and is so essential to gameplay that I cannot do without it. Thank you!

When trying to reorder columns in the Numbers tabs, there is a significant delay between dragging the column with the mouse and the column actually getting moved. This delay increases drastically with more columns being defined in the table and/or more pawns/animals being displayed in the table. By the time I have a colonist panel set up with skills, health info & operations, equipment, age, food/rest/mood, and a few stats, it can take up to 60 seconds for a dragged column to actually update in position, with the UI freezing/jerking during this time and the column-drag-position indicator not updating properly, resulting in the column sometimes ending up in the wrong position (or dropping the column back to the very end of the table instead of where it was intended to be dropped - possibly more common when the mouse isn't kept in the area where the drop was desired until the column is finally dropped even though the mouse button is no longer held down).

I managed to capture examples for both the "dropped at the end of the table" and the "dropped where requested" examples in this video: https://youtu.be/5hbK5Ptby14

The behaviour is as if the table columns are being re-sorted every few pixels that it gets dragged rather than just at the end of the drag movement or something similar, causing the game to lock up with excessive calculations during the drag. Once it finally "lets go" of the dragged column the game returns to fully responsive.

Note that this issue also existed in the 1.0 version of Numbers (which was the first version I'd used, so it may have been there from before then too), so it's been one of long standing. Originally I'd thought it may be PC related, but after replacing my PC recently the performance is completely unchanged.

OS: Debian Linux 10 (Buster). CPU: Ryzen 3950X. GPU: NVidia 2070 RTX Super. 32 Gb Ram. OS and game installed on a 1TB PCI-E 3 NVME M2 drive.

Mehni commented 4 years ago
dawnmist commented 4 years ago

Yes, this does still occur on the latest version on Steam.

No, it does not occur when rearranging pawns on the colonist bar (thanks - I hadn't known that was possible!).

dawnmist commented 4 years ago

Further testing: more pawns/animals in the table definitely make it a lot worse.

My prisoner panel with 3 pawns I can reorder columns with about a 5-10 second time to get them to move over, and the indicator does kind of follow the cursor to some degree.

My animal panel with 88 animals in it takes 30+ seconds to move a column, and does the same lock-up of the UI as in the example video, even though both tables have about the same number of columns.

So it's looking like the drag delays are a factor of (columns x rows)? The colonist bar effectively has a single row, so that may be why it isn't noticeably affected by the delays.

Mehni commented 4 years ago

https://www.dropbox.com/t/1i6yQdq5sKqRiLvQ

Try that and let me know if a) dragging still works b) it's any faster

dawnmist commented 4 years ago

I've given it a try (by replacing the Numbers.dll file in the steam/steamapps/workshop/content/294100/1414302321/1.1/Assemblies directory).

Yes, dragging still works, but sadly no it's not any faster - it's about the same, so much so that I went back and double-checked that I'd saved the replacement dll file to the right place, etc, to make sure I wasn't accidentally still running the original version by mistake.

Mehni commented 4 years ago

Well, that excludes one hypothesis.

I was hoping it was down to the way I had to change input behaviour from RimWorld's use of Unity's legacy Event to the newer Input system. Could have been that there was a difference in the way Debian handles its inputs. Sadly not.

Next step will be adding some caching, based on this comment

The behaviour is as if the table columns are being re-sorted every few pixels that it gets dragged rather than just at the end of the drag movement or something similar

Numbers doesn't re-sort every few pixels, but what does happen is that it recreates the functionality to do so. This might be heavy enough to cause the slowdown. Attached you'll find a new version which doesn't recreate the functionality time and again.

Try that and let me know if a) dragging still works b) it's any faster

Numbers.zip

For the sake of transparency: I cannot reproduce your issue locally. I have to rely on you to test.

dawnmist commented 4 years ago

I've given that a try. Dragging still works, and it's a little faster - seems to be about 20s to move a column on the animals tab rather than the 30s+ that it was.

I'm happy to help with testing it, given I'm seeing the issue consistently so it's easy for me to do the testing. :) I'm in Australia though, so timezone differences mean it'll often be the next day before I can get back to you.

Mehni commented 4 years ago

That's a solid improvement and I'm happy to hear that.

I'll need to analyse further to see what else can be done.

Mehni commented 4 years ago

Took out some of the code surrounding dragging. This should make it a bit simpler and quicker.

Numbers.zip

I hope this brings it to a more playable level. There are a few things left I can still try, but it's dwindling.

dawnmist commented 4 years ago

Thank you so much - that has definitely improved it a lot further. It's down to taking 10-14 seconds to drag a column in the animals tab - it can be as low as 5s if just moving over by one or two columns and up to 14s to move across most of the table, which is a huge improvement over what it had been.

Even if that ends up being all that you can do to help, it's a vast improvement over what it was in the beginning, so thank you very much for looking into it. :heart:

Mehni commented 4 years ago

I'll leave it as is for now, since the low-hanging fruit was plucked. I wish to focus a bit on MFI instead, and solving your issue 100% would take considerable time away from that.

Thanks for helping me test! Can I reopen this to call on your for testing if/when I get back to it?

dawnmist commented 4 years ago

Sure, I'm happy to help again if you get back to it. Thank you for the time you have put into it - it has helped immensely. :)