Search Unity

Poor performance

Discussion in 'Project Tiny' started by Streamfall, Jan 10, 2019.

  1. Streamfall

    Streamfall

    Joined:
    Aug 8, 2011
    Posts:
    28
    While my project runs in Firefox, I see that in Activity Monitor, FirefoxCP Web Content is hovering around 30% of CPU, while Firefox hovers around 8%. In Chrome, I noticed similar results.

    When I began the project, my intention was to make a banner of a single repeating sprite which reacted slightly to some windy noise and mouse over / clicks. Nothing fancy. Something that could simply load quickly and offer basic interaction for fun. Unfortunately, 30% of the processor is too much for a simple banner.

    I stripped all OnUpdate functionality, and found that the performance increased slightly but not significantly. I noticed that the DungeonZ project runs at about 10%. This project is similar because it simply uses a bunch of sprites. DungonZ uses the tile system, mine is just instantiated on a loop the first frame.

    My project contains a 100x100 image and a 32x32 image. The 32x32 image is repeated across the scene. I have commented all functionality and I have removed all modules except for Core2D, Image2D, Sprite2D, and Tweens.

    I would like to understand how to make Tiny Unity projects performant. Any ideas?

    EDIT:
    This seems to be directly related to the number of Entities generated in the first frame. I have it coded so that I can click on them to destroy them, and I can see a dramatic change as they are destroyed. With no entities left in my scene, I get about 10% instead of 30%;

    This leads to the question :
    Is it better to copy a child of an entity instead of creating lots of Entities? I'm going to try that next.
    Second question : would it be faster to create them in a tile grid?
     
    Last edited: Jan 10, 2019
  2. raymondyunity

    raymondyunity

    Unity Technologies

    Joined:
    Apr 30, 2018
    Posts:
    65
    What we're witnessing here is not the performance of the webpage but actually the browser interacting with the web server. I also see a high CPU usage, around 50%, running the DungeonZ sample from the Unity editor (Tiny Package 0.13.4-preview).

    This should not be a problem in a published game. If you navigate to the TinyExport folder and run the webpage and look at the CPU usage it should be around 10%. If you host it on another server such as "python -m simplehttpserver" (in directory). You'll notice that it should still be around 10%. There seems to be something going on with the web server we create while using the Unity editor (OSX only). We are looking into this.

    So try those steps and let us know what you see. Thank you and we really appreciate this feedback!
     
  3. Streamfall

    Streamfall

    Joined:
    Aug 8, 2011
    Posts:
    28
    Hi Ray,
    I gave this a go. It still seems to be running at around 25% when ran from the TinyUnity Export folder. I truly appreciate you looking into this.

    I've been looking for a way to 1) instantiate an entity 2) copy that entity's child instead of the whole Entity Group within the loop. I don't know if it would help but do you have any insight into it?

    Edit :
    I have 'Play Mode' turned off, so the browser should not be interacting with a webserver. Do I understand that correctly?

    Edit :
    This is how I'm attempting to instantiate the child of the entity group.
    let instance = ut.EntityGroup.instantiate(this.world, "game.Card")[0];
    let a = this.world.instantiateEntity(instance[1]);

    Results in call stack :
    Successfully compiled asm.js code (loaded from cache in 49ms) runtime.js
    runtime version: internal main.js:6:1
    [LiveLink] connecting... wsclient.js:31:9
    Initializing Playable Ad runtime.js:142755:4
    setCanvasSize 1170 317 gl runtime.js:142874:3
    WebGL context is webgl2. runtime.js:142932:5
    EntityManager::instantiateEntities: Attempted to delete invalid entity NONE (passed at index 0 in the array to destroyEntities() function) Callstack: ut.WorldBase.prototype.instantiateEntity (http://localhost:19050/runtime.js:127208:2) GridControl.prototype.OnUpdate/< (http://localhost:19050/~project/Tin...velopment/ScriptAssemblies/tsc-emit.js:204:29) World.prototype.forEach (http://localhost:19050/runtime.js:127754:8) GridControl.prototype.OnUpdate (http://localhost:19050/~project/Tin...velopment/ScriptAssemblies/tsc-emit.js:198:13) ComponentSystem.prototype._MakeSystemFn/< (http://localhost:19050/bindings.js:1892:17) dynCall_v (http://localhost:19050/runtime.js:125155:1) mainLoop (http://localhost:19050/runtime.js:1688:3) runtime.js:980:2
    Assertion failed: exists(entities), at: C:/Users/Abdul/Documents/tiny/Runtime/modules/core/src/arch/EntityManagerAssertions.cpp,43, runtime.js:126115:3
    Assertion failed: exists(entities), at: C:/Users/Abdul/Documents/tiny/Runtime/modules/core/src/arch/EntityManagerAssertions.cpp,43, runtime.js:126116:3
    uncaught exception: abort("Assertion failed: exists(entities), at: C:/Users/Abdul/Documents/tiny/Runtime/modules/core/src/arch/EntityManagerAssertions.cpp,43,"). Build with -s ASSERTIONS=1 for more info.
    [LiveLink] connected wsclient.js:31:9
     

    Attached Files:

    Last edited: Jan 10, 2019
  4. raymondyunity

    raymondyunity

    Unity Technologies

    Joined:
    Apr 30, 2018
    Posts:
    65
    The "Enable Play Mode" menu item allows a user to access Live-Link mode. If you "build and run", a local http server is created to host your project. So if you're accessing your project via "localhost:19050 (default port)" you will see the odd CPU usage in OSX.

    If you launched the html file directly from menu using Firefox your process name should be something like "FirefoxCP file://Content". This mean it is not using a webserver to serve the webpage. If you still get a high usage, please either report the project using the bug tool (I can pick it up from there) or just DM me your zipped project.

    May I know why your CPU usage is so critical? What is your use case? This will change when C# comes around.
     
    frankprogrammer likes this.
  5. Streamfall

    Streamfall

    Joined:
    Aug 8, 2011
    Posts:
    28
    Thanks again.
    CPU usage here is critical because it is intended to be a lightweight header, and I intend to apply some perlin noise and the like eventually to make it interesting. I don't want it to start off heavy since it really isn't the focal point of the site. My intentions long term is to make small games that reside in the sides of websites, and I'd like them to be as light as possible.

    I'm going to go ahead and try to export and send the project over to you over DM. I suspect that sending only the sub folder for the game would be appropriate?
     
  6. raymondyunity

    raymondyunity

    Unity Technologies

    Joined:
    Apr 30, 2018
    Posts:
    65
    Just to summarize here if people are finding more information about CPU performance. There is an issue with high CPU usage (in OSX) when seemingly rendering just a bunch of sprites in the project. This will change when C# arrives.

    PS: It was not your code causing the issue.
     
    leeham9 and facundo_unity961 like this.