Skip to content

Speed up PrintBuffer::flush()#811

Open
xilec wants to merge 2 commits intogyscos:mainfrom
xilec:speed-up-buffer-flush
Open

Speed up PrintBuffer::flush()#811
xilec wants to merge 2 commits intogyscos:mainfrom
xilec:speed-up-buffer-flush

Conversation

@xilec
Copy link
Copy Markdown
Contributor

@xilec xilec commented Feb 23, 2025

  • Moved persistent flag to type level. Now compiler knows it value at compile time and optimize it away. It almost have no impact on performance, but it helps to split implementation of flush_to_backend() on 2 cases and may helps to experiment and optimize in the future.
  • Replaced clone_from_slice() with manual copy actual cell to frozen. First of all, I want to note Cell is not Copy, and can't be copied as 1 slice of memory, therefore I suppose clone_from_slice() unfolded by compiler just in loop of clones from actual cell to frozen. Мoving this clone() to the existing loop like in PR changes usually we skip many call of clone(), because of in common case changing only part of screen, and amortize cloning by parallel execution on cpu instruction level.

By my tests of performance this changes give about 20-30% speed up

For tests I measure time of invocation PrintBuffer::flush() on different examples:

  • lorem - not modified example, tested just scrolling
  • lorem (war and peace) - changed test to just English text that fill allmost all screen, tested just scrolling
  • progress - not modified example, tested just changes from progress changing
  • progress - changed count of progress bars to 200, tested just changes from progress changing

time_lorem_(war_and_peace)_after.txt
time_lorem_(war_and_peace)_before.txt
time_lorem_after.txt
time_lorem_before.txt
time_progress_after.txt
time_progress_before.txt
time_progress_mod_after.txt
time_progress_mod_before.txt

UPDATE:

Added compare styles by value. It reduces about 3 additional microseconds (6%)

@xilec
Copy link
Copy Markdown
Contributor Author

xilec commented Apr 15, 2025

@gyscos, can you review this PR?

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.

1 participant