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

Visal debugging performance #799

Closed
FNGgames opened this issue Sep 26, 2018 · 17 comments
Closed

Visal debugging performance #799

FNGgames opened this issue Sep 26, 2018 · 17 comments
Assignees
Milestone

Comments

@FNGgames
Copy link

FNGgames commented Sep 26, 2018

Ideas / suggestions for a "performance mode" version of visual debugging (VD).

Problem: VD currently very demanding for a large number of entities due to the cost of creating and destroying the gameobjects used to represent them.

Here are a few of my thoughts:

  1. Pool the gameobjects used for VD

  2. Create only the root systems inspector gameobject by default then add buttons to "expand" or "collapse" sub-features which would create/destroy the child gameobjects that represent the sub-features (though i dont think systems profiling is the real culprit here)

  3. Create no gameobjects for individual entities, instead, just use the single context gameobjects by default, list all the currently defined groups in the inspector, list their entity count, then provide a button to debug the group which would then create the gameobjects as usual, but only for the requested group. Remove the gameobjects again when the debug group button is unchecked.

  4. Allow on-the-fly custom groups to be made and then debugged as in (3). This could perhaps be done by providing 3 arrays to fill, one of the components in AllOf, the second AnyOf and third NoneOf. Generate the group by assembling it from those pieces then provide the "debug this group" check box as before.

  5. ToString() for every component to produce the name for the gameobject seems a bit heavy and wasteful, maybe there's a better way to search them, instead of using unity's string search field, perhaps we could use groups as described above instead. Then we could get rid of the need to ToString the entities to write their names out (again, no idea whether this is an useful optimisation or not, just thinking aloud).

Ideas / comments welcome.

@WeslomPo
Copy link

Huge problem that name for entities generates every frame by ToString (5 problem in the list). This is first that need to be fixed.

@CCludts
Copy link

CCludts commented Sep 27, 2018

Out of curiosity, did anyone do some in-depth profiling to figure out what makes VD so heavy? A quick glance at the profiler seems to suggest ToString is the main culprit in our project (agreeing with @WeslomPo). Seems slightly strange, since ToString already has a cache built-in, and shouldnt be that expensive.

The way we 'fixed' things in our project is by disabling VD, and have a button to enable to at runtime. It's a mediocre fix though, it would be awesome if there's a low-level modification to make it more performant with large amounts of entities.

@FNGgames
Copy link
Author

The cache for ToString is likely overwritten every frame if an entity changes at all, it has to walk every component and build a string out of all their ToString values. Just guessing here though, didn't look at the source.

@roygear
Copy link
Contributor

roygear commented Sep 29, 2018

The bad boy is ToString() in Update().

Here is my solution:
In class EntityBehaviour, use delegate OnComponentAdded and OnComponentRemoved instead of Update(). That will greatly reduce the calling of ToString(). After change, I can run 3000+ entities which contain 10 components smoothly in my test scene.

Source :
https://gist.github.com/roygear/f7eae9fe2f13792f0468657aa4428c31

Compiled dll based on 1.8.2
Entitas.VisualDebugging.Unity.dll.zip

@sschmid
Copy link
Owner

sschmid commented Sep 29, 2018

EntityBehaviour can be expensive when there are thousands of entities.

  • Updating the GameObjects name is expensive
  • If the Entity changes each frame entity.ToString() is very expensive

For comparison:
left: as is right now
right: no ToString()

entitas-visualdebugging

@sschmid
Copy link
Owner

sschmid commented Sep 29, 2018

I tried not to change too much and do small improvements. By simply ignoring component.ToString(), which is probably not often used (e.g. Entity_0(*1)(Position(1, 2, 3))), we can safe 40% already.

@roygear
Copy link
Contributor

roygear commented Sep 30, 2018

In fact, the full component names cannot displayed on vertical layout. There are 10 components on the left, but displayed 3 to 4 maximum usually. Now, I have the right one.
untitled-1

@mchamplain
Copy link

Maybe setting a name when creating the entity would be more useful that displaying the components names?
var e = gameContext.CreateEntity("player");

@sschmid
Copy link
Owner

sschmid commented Sep 30, 2018

btw, the main reason I include all components is to able to search and filter entities

@zhuchun
Copy link

zhuchun commented Oct 2, 2018

Good post! There're only a few entities in my current project but every time I click on any entity the inspector will be frozen for half a minute, I guess these are related.

@FNGgames
Copy link
Author

FNGgames commented Oct 2, 2018

btw, the main reason I include all components is to able to search and filter entities

What do you think about susing groups to choose which things get displayed?
You could have an "all" option or narrow them down by group?

@sschmid sschmid added this to the Entitas 1.8.3 milestone Oct 5, 2018
@ghost ghost assigned sschmid Oct 24, 2018
@ghost ghost added the in progress label Oct 24, 2018
@sschmid
Copy link
Owner

sschmid commented Oct 24, 2018

Hi, you might wanna pull from
#799-visual-debugging-performance

  • reduced e.ToString() cache invalidation
  • always using component.ToString()
  • added object pool for EntityBehaviour

I'd like to have some feedback from you guys, if the performance is better and if it's good enough, or if there are more areas that need opimization. Thanks!

@sschmid
Copy link
Owner

sschmid commented Oct 24, 2018

You're still able to use the hierarchy search and custom component.ToString() still works, but the overall performance should be way better now.

See diff
https://github.com/sschmid/Entitas-CSharp/compare/feature/%23799-visual-debugging-performance

@FNGgames
Copy link
Author

Are you going to merge this into release in the future? Thanks for responding to this issue

@sschmid
Copy link
Owner

sschmid commented Oct 25, 2018

Yes, that’s the plan. I just wanted to hear feedback already because I don’t have projects where visual debugging is an issue.

@sschmid
Copy link
Owner

sschmid commented Oct 25, 2018

For your convenience, here' a precompiled version of the latest version incl. the Visual Debugging improvements:

Entitas.zip

@sschmid
Copy link
Owner

sschmid commented Nov 3, 2018

Any feedback welcome ;)

@ghost ghost added needs review and removed in progress labels Nov 3, 2018
@ghost ghost removed the needs review label Nov 3, 2018
@sschmid sschmid added this to Entitas Jul 2, 2023
@github-project-automation github-project-automation bot moved this to Todo in Entitas Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

7 participants