Skip to content

chore: optimize avatar names#833

Merged
AjimenezDCL merged 19 commits intomasterfrom
chore/optimize-avatar-names
Jul 26, 2021
Merged

chore: optimize avatar names#833
AjimenezDCL merged 19 commits intomasterfrom
chore/optimize-avatar-names

Conversation

@AjimenezDCL
Copy link
Copy Markdown
Contributor

@AjimenezDCL AjimenezDCL commented Jul 22, 2021

Fixes #825

To optimize the Avatar Names we are going to:

  • User the same canvas for each name
  • Sort the pieces so we can batch the draws of the containers, the text and the voice chat icon.

Approach:

  1. Create a new HUD called AvatarNames.
  2. Use the DataStore to keep a PlayerStatus collection.
  3. Minimap refactoring to use the new PlayerStatus collection.
  4. AvatarNameHUD implementation.

It must be tested with this Kernel:
decentraland/explorer#2503

Test Link: https://play.decentraland.zone/branch/chore/avatar-names-optimization/index.html?renderer=urn:decentraland:off-chain:renderer-artifacts:chore/optimize-avatar-names

@AjimenezDCL AjimenezDCL self-assigned this Jul 22, 2021
@github-actions
Copy link
Copy Markdown
Contributor

@AjimenezDCL
Copy link
Copy Markdown
Contributor Author

AjimenezDCL commented Jul 22, 2021

Measurements

Still WIP. Benchmark in Unity Editor

Standing Still

Before Optimization
PerformanceMeter - Data report step 2 - Processed values:
 * PERFORMANCE SCORE (0-100) -> 74,49
 * average FPS -> 29,59333
 * highest FPS -> 33
 * lowest FPS -> 25
 * 50 percentile (median) FPS -> 30
 * 95 percentile FPS -> 33
 * total hiccups (>0,05ms frames) -> 3 (0,33% of frames were hiccups)
 * total hiccups time (seconds) -> 0,2143326
 * total frames -> 900
 * total frames time (seconds) -> 30,00287
After Optimization
PerformanceMeter - Data report step 2 - Processed values:
 * PERFORMANCE SCORE (0-100) -> 75,92
 * average FPS -> 31,42437
 * highest FPS -> 36
 * lowest FPS -> 26
 * 50 percentile (median) FPS -> 32
 * 95 percentile FPS -> 35
 * total hiccups (>0,05ms frames) -> 5 (0,53% of frames were hiccups)
 * total hiccups time (seconds) -> 0,3589172
 * total frames -> 952
 * total frames time (seconds) -> 30,00278

Moving around

Before Optimization
PerformanceMeter - Data report step 2 - Processed values:
 * PERFORMANCE SCORE (0-100) -> 73,21
 * average FPS -> 28,47691
 * highest FPS -> 33
 * lowest FPS -> 22
 * 50 percentile (median) FPS -> 29
 * 95 percentile FPS -> 32
 * total hiccups (>0,05ms frames) -> 9 (1,04% of frames were hiccups)
 * total hiccups time (seconds) -> 0,5629196
 * total frames -> 866
 * total frames time (seconds) -> 30,0013
After Optimization
PerformanceMeter - Data report step 2 - Processed values:
 * PERFORMANCE SCORE (0-100) -> 74,98
 * average FPS -> 30,23965
 * highest FPS -> 35
 * lowest FPS -> 25
 * 50 percentile (median) FPS -> 30
 * 95 percentile FPS -> 35
 * total hiccups (>0,05ms frames) -> 4 (0,44% of frames were hiccups)
 * total hiccups time (seconds) -> 0,2732468
 * total frames -> 918
 * total frames time (seconds) -> 30,0129

@AjimenezDCL
Copy link
Copy Markdown
Contributor Author

Measurements

Benchmark in Build

Before Optimization
PerformanceMeter - Data report step 2 - Processed values:
 * PERFORMANCE SCORE (0-100) -> 26.64
 * average FPS -> 18.37345
 * highest FPS -> 19
 * lowest FPS -> 11
 * 50 percentile (median) FPS -> 19
 * 95 percentile FPS -> 19
 * total hiccups (>0.05ms frames) -> 437 (77.35% of frames were hiccups)
 * total hiccups time (seconds) -> 23.67953
 * total frames -> 565
 * total frames time (seconds) -> 30.0313
After Optimization
PerformanceMeter - Data report step 2 - Processed values:
 * PERFORMANCE SCORE (0-100) -> 39.05
 * average FPS -> 19.19595
 * highest FPS -> 20
 * lowest FPS -> 11
 * 50 percentile (median) FPS -> 19
 * 95 percentile FPS -> 20
 * total hiccups (>0.05ms frames) -> 319 (53.89% of frames were hiccups)
 * total hiccups time (seconds) -> 16.94389
 * total frames -> 592
 * total frames time (seconds) -> 30.02672

Copy link
Copy Markdown
Contributor

@D4rWiNSS D4rWiNSS left a comment

Choose a reason for hiding this comment

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

LGTM! Some suggestions were added.

I think we should somehow ( maybe each X seconds ) change the names of the avatars when we are moving and we are above the max numbers of avatar names.

Imagine that you are in a concert and we are moving on to where our friends are. So we are moving from the entrance to the other part of the concert. You will want to see the avatar names of the nears players and not the first 200 avatars names.

Take this into account for the future!


private void OnEnable()
{
canvasRect.GetComponent<Canvas>().sortingOrder = -2;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should move this to somewhere common to the project like Settings, So in the future, if we need to change the sorting order in other parts of the project we have some visibility about the current canvas ordering. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure about that, this is an specific sorting set for the AvatarNames. I dont think any other part of the project should be aware of what sorting order does the AvatarNames canvas have.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As you wish!


public void DestroyUIElements()
{
Object.Destroy(background.gameObject);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't we use GameObject.Destroy instead of Object in unity objects?

Copy link
Copy Markdown
Contributor Author

@AjimenezDCL AjimenezDCL Jul 26, 2021

Choose a reason for hiding this comment

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

Destroy is a member of Object. GameObject has it because inherits Object.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, but Unity uses an implementation where he passes the time to be destroyed, not sure if it makes any change though

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I mean, GameObject doesn't override Destroy. It's the same call

protected override IEnumerator TearDown()
{
if (hudView != null)
Object.Destroy(hudView.gameObject);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here, GameObject instead of Object?

Copy link
Copy Markdown
Contributor

@sandrade-dcl sandrade-dcl left a comment

Choose a reason for hiding this comment

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

Reviewed and tested, LGTM! I only left some suggestions/doubts. Good work.

private MinimapMetadata.MinimapUserInfo avatarUserInfo = new MinimapMetadata.MinimapUserInfo();
bool initializedPosition = false;

private PlayerStatus playerStatus = null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In order to avoid confussions, maybe a better name for this playerStatus would be avatarStatus? As this data is managed by any avatar in the world and not only by our avatar... What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It contains information about the player, such as name and the voice chat status along the position. I think it would be more confussing to have it named avatarStatus.

Comment on lines +145 to +146
if (playerStatus != null)
playerStatus.worldPosition = entity.gameObject.transform.position;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Couldn't we do this position update in the OnEntityTransformChanged() instead of do it in each frame?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The entity transform position is not where the Avatar is rendered, we interpolate the target position to make it smoothly. We actually have to do it each frame or the AvatarName will be lagging behind. A nice "side-effect" is that the minimap is now smoother as well (since it can use this data).

@AjimenezDCL
Copy link
Copy Markdown
Contributor Author

LGTM! Some suggestions were added.

I think we should somehow ( maybe each X seconds ) change the names of the avatars when we are moving and we are above the max numbers of avatar names.

Imagine that you are in a concert and we are moving on to where our friends are. So we are moving from the entrance to the other part of the concert. You will want to see the avatar names of the nears players and not the first 200 avatars names.

Take this into account for the future!

@Suduck Yeah I was thinking the same but as I started benchmarking I noticed we can drastically increase the number of Avatar Names in screen (thanks the the batching of the UI parts). It's a nice suggestion but it wouldn't have much use until we can comfortably have more than 200 users on screen.

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.

Optimize avatar names

4 participants