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

[GuiAdvancedScrollText] Improve performance #1946

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

oznogon
Copy link
Contributor

@oznogon oznogon commented Mar 18, 2023

Re: #1939

This refactors GuiAdvancedScrollText to improve render performance.

  • Font prep is moved to addEntry, and FontPreparedStrings are stored in the entries. This means fonts for an entry are prepared once upon the entry's addition, not each frame. This improves render performance, especially with large texts.
  • Font prep is repeated across all entries only if the window width changes.
  • Content outside the bottom of the scroll rect is ignored on the text-rendering step, rather than rendered and then clipped. This improves render performance when scrolling to the top of the text.
  • max_prefix_width is calculated upon entry addition rather than each frame.

Testing on a variety of systems with a 10,000-entry log, this maintains:

  • 20fps on a 12th-gen/16-thread i5 on Intel graphics, with power-saving enabled (previously: 2.8)
  • 40fps on a 12th-gen/16-thread i5 on Intel graphics (previously: 4)
  • 51fps on a 16-thread Ryzen 9/RTX 3060 (previously: 9)

Known issues:

  • The latest-line view on Relay doesn't render correctly upon screen load. Expanding and minimizing the log view on Relay resolves this.
  • Resizing the window with a large text is as expensive as before this PR, since this is now the only time the entire entries list is prepared at once.
  • max_prefix_width is retained even if the largest prefix-width entry is removed from the log. This is potentially trivial to fix.

Prepare fonts for entries only when adding an entry, rather than
for every entry on every frame.
Re-prep fonts to reflow and recalculate entry height when the
window width changes. This causes significant performance impacts
when resizing the window with a large log.
@oznogon
Copy link
Contributor Author

oznogon commented Mar 18, 2023

Ran out of spare time on this, so I'm posting it up in case someone can improve on it.


//Draw the visible entries
float draw_offset = -scrollbar->getValue();
float draw_offset = -scrollbar->getValue() + text_size + 12.0f;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bad kludge to realign text now that the positioning lives in the Entry rather than recalculated each onDraw.

@oznogon
Copy link
Contributor Author

oznogon commented Mar 18, 2023

#1947 was caught while doing this. An example of a potential fix involves checking the prefix text as well as the entry text, which requires adding a getEntryPrefix() function to GuiAdvancedScrollText. That would limit collisions to only entries with the same text at the same time in the ship's log. Another fix would be adding a UID to entries and checking that instead of the text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant