Skip to content

fix: Noticeable hiccups when receiving a chat message and the chat history is long#850

Merged
sandrade-dcl merged 4 commits intomasterfrom
fix/Noticeable-hiccups-when-receiving-a-chat-message-and-the-chat-history-is-long
Jul 28, 2021
Merged

fix: Noticeable hiccups when receiving a chat message and the chat history is long#850
sandrade-dcl merged 4 commits intomasterfrom
fix/Noticeable-hiccups-when-receiving-a-chat-message-and-the-chat-history-is-long

Conversation

@sandrade-dcl
Copy link
Copy Markdown
Contributor

@sandrade-dcl sandrade-dcl commented Jul 27, 2021

What does this PR change?

Fix #123

Seems to be that when the chat history gets quite long, every new chat message received takes some milliseconds in processing, and that causes noticeable hiccups

Main cause of the hiccups

  • Each time a message entered the chat, we was forcing to update ALL the existing entries layouts with Utils.ForceUpdateLayout(transform as RectTransform, delayed: false), that had having a huge impact on the performance when the chat had accumulated a lot of messages.
  • After a message entered the chat, we was setting the vertical position of the HUD scroll to 0 with scrollRect.verticalNormalizedPosition = 0, and it was affecting negatively to the performance.

Implemented solutions

  • Now, instead of always update all the entries each time a new message entered the chat, we only update the new added entry and, if it is necessary, the entries whose position was changed during the re-ordering by timestamp.
  • Now, before setting the vertical position of the HUD scroll to 0, we check if the current position is grater that 0. In this way we will only apply this action when it is needed.
  • We have changed the maximum number of entries in the chat (MAX_CHAT_ENTRIES) from 100 to 30. It will make the HUD lighter.

Metrics obtained from the AddEntry(...) action hiccups

  • BEFORE: Hiccups up to ~287.50ms per each entry added in the chat.
  • NOW: Hiccups up to ~3.45ms per each entry added in the chat.

How to test the changes?

  1. Go to: https://play.decentraland.zone/index.html?renderer=urn:decentraland:off-chain:renderer-artifacts:fix/Noticeable-hiccups-when-receiving-a-chat-message-and-the-chat-history-is-long
  2. Test the world and private chats.

Our Code Review Standards

https://github.com/decentraland/unity-renderer/blob/master/docs/code-review-standards.md

@sandrade-dcl sandrade-dcl self-assigned this Jul 27, 2021
Copy link
Copy Markdown
Member

@pravusjif pravusjif left a comment

Choose a reason for hiding this comment

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

awsome job!

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.

Noticeable hiccups when receiving a chat message and the chat history is long

3 participants