Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Worker Inspector window & Entity List #1375

Merged
merged 7 commits into from
May 29, 2020

Conversation

jamiebrynes7
Copy link
Contributor

@jamiebrynes7 jamiebrynes7 commented May 27, 2020

Description

This PR is the first in a series for the Worker Inspector window. In it, we find:

  • The window definition itself
  • A UI element for listing and selecting entities.
  • Searching over the list of entities by entity ID and entity type (metadata)
  • Relatively efficient list rebuilding
    • Only rebuilds when entities have been added/removed.
    • With 10k SpatialOS entities in the Editor => ~2-3ms for a full rebuild
    • With 100k SpatialOS entities in the Editor => ~20-30ms for a full rebuild
    • (On a i7 7700k)
    • Possible optimizations in the future would be to use the EntityManagerDiffer to track changes, but this would require the underlying data storage to be equipped for fast additions/removals. For now, I feel what we have is acceptable performance
    • Or alternatively jobify the list building.
  • Some other misc changes (sortable EntityId structs, hacky ViewVersion for diff tracking)

A quick screenshot, the right hand panel will be used for displaying the detail for a given entity.

image

Tests

  • Some quick perf tests on my local machine, and for searching.
  • Unit tests for the searching.

Documentation

  • I'll add a changelog once the rest is implemented

@improbable-prow-robot improbable-prow-robot added jira/no-ticket Indicates a PR has no corresponding JIRA ticket do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels May 27, 2020
@improbable-prow-robot improbable-prow-robot added A: core Area: Core GDK size/XL Denotes a PR that changes 300-599 lines, ignoring generated files. labels May 27, 2020

private void OnEntitySelected(EntityId entityId)
{
UnityEngine.Debug.Log($"Selected {entityId}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Debug stuff that is removed later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, just a placeholder for now.


public EntityList()
{
const string uxmlPath = "Packages/io.improbable.gdk.debug/WorkerInspector/Templates/EntityList.uxml";
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have any kind of system or central place to put hard coded references to other packages/assets? Not saying we need to do that here if it's a one-off, but seeing this made me think of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope we don't. Tbh I'd be against a central place since its only referenced here and the locality is nice.

{
unchecked
{
return (EntityId.GetHashCode() * 397) ^ (Metadata != null ? Metadata.GetHashCode() : 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is 397 a magic number? I'm not familiar with what it means here.

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 the magic auto-impl of GetHashCode() by Rider. I believe 397 is a prime number which plays some role in this.

rootVisualElement.styleSheets.Add(stylesheet);

worldSelector = rootVisualElement.Q<WorldSelector>();
worldSelector.OnWorldChanged += OnWorldChanged;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to manually remove these callbacks if the window is closed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the window is closed, the world selector element is removed along with it, so its all GC'ed

@improbable-prow-robot improbable-prow-robot added size/XXL Denotes a PR that changes 600+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 300-599 lines, ignoring generated files. labels May 27, 2020
@jamiebrynes7 jamiebrynes7 force-pushed the feature/worker-inspector-window branch from bf86df6 to 5489e0c Compare May 27, 2020 15:51
@jamiebrynes7 jamiebrynes7 marked this pull request as ready for review May 27, 2020 15:51
@improbable-prow-robot improbable-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 27, 2020
@jamiebrynes7 jamiebrynes7 force-pushed the feature/worker-inspector-window branch from 5489e0c to f36e21e Compare May 29, 2020 11:24
using Improbable.Gdk.Core;
using Unity.Collections;
using Unity.Entities;
using Unity.Profiling;
Copy link
Contributor

Choose a reason for hiding this comment

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

still need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, there are ProfilerMarkers on L12-13.

SonarCloud will flag unused imports now as a code smell 😁

private EntityQuery query;
private EntitySearchParameters searchParameters;

public void ApplySearch(EntitySearchParameters searchParameters)
Copy link
Contributor

Choose a reason for hiding this comment

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

ApplyFilter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer ApplySearch since the parameter is of type EntitySearchParameters

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

39.3% 39.3% Coverage
0.0% 0.0% Duplication

@jamiebrynes7 jamiebrynes7 merged commit 8e37957 into develop May 29, 2020
@improbable-prow-robot improbable-prow-robot deleted the feature/worker-inspector-window branch May 29, 2020 13:23
@jamiebrynes7 jamiebrynes7 mentioned this pull request Jun 1, 2020
5 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A: core Area: Core GDK jira/no-ticket Indicates a PR has no corresponding JIRA ticket size/XXL Denotes a PR that changes 600+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants