Giter Site home page Giter Site logo

Comments (7)

No3371 avatar No3371 commented on June 11, 2024

I am working on managed AI worker which spawns 715 entities, modify the position components and let SpatialOS update the data to runtime, every frame.

So it turns out it's because a managed worker runs way faster then one running inside UnityEditor, so it generate enormous traffic toward the runtime.

After limit targetFrameRate to 60, the memory usage stays at about 4GB.

from gdk-for-unity.

No3371 avatar No3371 commented on June 11, 2024

Unfortunately I have to reopen this since the memory usage will randomly grows, like, after staying at 4GB for 5 minutes, it suddenly goes up to 13GB, then after 2 minutes, it goes up to 15GB.

Continuing to do these tests, will let you know the results.

  • [DONE] External worker in UnityEditor without opening inspector (Issue not reproduced in 25 mins)
  • [DONE] Managed worker without opening inspector (Issue not reproduced in 30 mins)
  • [PEDNING] External worker in UnityEditor opening inspector
  • [DONE] Managed worker opening inspector (Issue reproduced in 8 mins, memory usage grown to 9GB)

The code of the system setting Position for reproducing purpose:

using Improbable;
using Improbable.Gdk.Core;
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Transforms;

[UpdateInGroup(typeof(SpatialOSUpdateGroup))]
public class SpatialPositionFromTranslationSystem : SystemBase
{
    EntityQuery query;
    protected override void OnCreate()
    {
        query = GetEntityQuery(ComponentType.ReadOnly<Translation>(), ComponentType.ReadWrite<Position.Component>(), ComponentType.Exclude<NewlyAddedSpatialOSEntity>());
        query.SetChangedVersionFilter(typeof(Translation));
    }
    protected override void OnUpdate()
    {
        SyncJob job = new SyncJob
        {
            Translation_Type = GetArchetypeChunkComponentType<Translation>(),
            Position_Type = GetArchetypeChunkComponentType<Position.Component>()
        };
        job.ScheduleParallel(query).Complete();
    }

    [BurstCompile]
    protected struct SyncJob : IJobChunk
    {
        [ReadOnly] public ArchetypeChunkComponentType<Translation> Translation_Type;
        public ArchetypeChunkComponentType<Position.Component> Position_Type;
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var translations = chunk.GetNativeArray<Translation>(Translation_Type);
            var positions = chunk.GetNativeArray<Position.Component>(Position_Type);
            var cache = new Position.Component();
            var coordCache = new Coordinates();
            for (int i = 0; i < translations.Length; i++)
            {
                coordCache.CopyFromUnityFloat3(translations[i].Value);
                cache.Coords = coordCache;
                positions[i] = cache;
            }
        }
    }
}

public static class SpatialCoordsExtentsion
{
    public static float3 ToUnityFloat3 (this global::Improbable.Coordinates source)
    {
        return new float3((float) source.X, (float) source.Y, (float) source.Z);
    }
    public static global::Improbable.Coordinates FromUnityFloat3 (float3 source)
    {
        return new global::Improbable.Coordinates(source.x, source.y, source.z);
    }
    public static void CopyFromUnityFloat3 (this ref global::Improbable.Coordinates dest, float3 source)
    {
        dest.X = source.x;
        dest.Y = source.y;
        dest.Z = source.z;
    }
}

from gdk-for-unity.

No3371 avatar No3371 commented on June 11, 2024

[DONE] Managed worker opening inspector (Issue reproduce in 8 mins, memory usage grows to 9GB)

I've reproduced the random memory leak, it happens when Inspector opened.

Another minor issue along with this:
Under heavy load Entity count in Inspector is being decreased overtime. The entity count decreased to 6XX, but shows 715 if I opens with Chrome at the time, then start decreasing as well after minutes.

Not sure if these only happens when CPU is 100% loaded. (When inspector opens running these tests, CPU are at 100% all the time)

from gdk-for-unity.

zeroZshadow avatar zeroZshadow commented on June 11, 2024

Does this happen with just the Inspector, or also Inspector V2?
When you mention CPU and memory usage, is this for the worker or the runtime process?

Note that sening an update on Position is special and rather heavy, as this will cause the runtime to re-evaluate all subscriptions made through QBI queries.

from gdk-for-unity.

No3371 avatar No3371 commented on June 11, 2024

Does this happen with just the Inspector, or also Inspector V2?

I did not test with InspectorV2, I've tried it multiple times though, but it's not as intuitive as V1 😅

When you mention CPU and memory usage, is this for the worker or the runtime process?

It's the java process. It always occupy a lot of CPU usage, I am thinking it may be related to what you said below.

Note that sening an update on Position is special and rather heavy, as this will cause the runtime to re-evaluate all subscriptions made through QBI queries.

Thank you, that's very valuable info!
Does this means I can give up Immediate updating of Inspector positions and use custom position component for performance?

from gdk-for-unity.

zeroZshadow avatar zeroZshadow commented on June 11, 2024

Yes it is recommended to only update Position at a low rate, and use a custom component for the actual position of the entity.
Position is used for things like queries, the inspector, and for the initial prefab spawn if you use the default gameobject creator.

from gdk-for-unity.

No3371 avatar No3371 commented on June 11, 2024

OK, thanks for the heads up.

I am in the progress to finish up a demo project and moving to cloud, so may not be able to reproduce the issue in near future, as we yet have a conclusion, I'll let this remain opened, will definitely report back if it happens again.

from gdk-for-unity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.