Editbox Lag
« on: 24 November 2016, 15:31:46 »
Hello.
Just started to use TGUI today and created one EditBox.
Tested it for a 10 seconds and encountered a problem.

Steps to reproduce:
1. Type enough letters inside EditBox so they won't fit anymore (text started to scroll).
2. Try to select the text with mouse and move mouse left/right to select/deselect parts of text.

Massive FPS drop appears to me (like, from 60 stable (framelimit) to 20-30).
If there are not many letters than I don't see any lag. Not sure if it's because of amount of characters or just because of scrolling.

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Editbox Lag
« Reply #1 on: 24 November 2016, 15:51:38 »
It seems to be because of the amount of characters and unrelated to the scrolling.
I need more than 100 characters to have a very noticable framedrop here which is more than you normally put in it, but it would of course be better if there wouldn't be an issue with the amount of characters.

Looking over the code it didn't take me long to find the issue: there is a function that takes the mouse position as input and returns the character in the text where the mouse is which is written in a very naive and unoptimized way.

It won't be fixed anywhere soon though. While I was rewriting text handling in 0.8-dev I also came across this part of the code and wanted to optimize it. It turned out that I didn't even fully understand how the code works anymore and eventually I decided to leave it like it currently is.

The best I can do right now is put it on the todo list and when it ever gets optimized you could just update to the new patch release and the problem would be gone.

Re: Editbox Lag
« Reply #2 on: 24 November 2016, 16:10:29 »
Okay, thanks for the reply.
I noticed fps drop even with something like 30 characters.
Is it the same for TextBox?
Normally TextBox could contain more characters than EditBox does without lags.

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Editbox Lag
« Reply #3 on: 24 November 2016, 16:16:58 »
TextBox is highly optimized to support many characters.
In tgui 0.5 there was indeed a similar issue where selecting text in TextBox with more than 500 characters would freeze the program for a moment (getting less than 1 fps), but this issue was fixed when rewriting the class in 0.6. It should handle up to 100 000 characters fine now.

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Editbox Lag
« Reply #4 on: 16 December 2016, 22:34:10 »
This issue has been fixed on the master branch on github. You can dowload the ZIP and build tgui yourself or wait several weeks/months until the release of TGUI 0.7.3.

It is not as optimized as TextBox, but it will be good enough now. If you go over a thousand characters you will again start seeing fps drops but that is not really a realistic case. Maybe one day I'll improve the code to track what the first and last displayed character is so that I can make the code run independent of the amount of characters, but nobody should have any performance problems anymore with the current implementation.