Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Multiple System vs Methods

Discussion in 'Data Oriented Technology Stack' started by Antypodish, Jun 21, 2019.

  1. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    9,291
    General Case

    I have number of systems.
    Some of them easily reach multi thousands lines of code.
    Other may be relatively small.
    With single, and multi-threaded jobs, and burstable where possible.
    All generally works.

    Problem I starting to facing now, when adding some new systems, which need to be executed if the specific sequence. I do control that with Either UpdateAfter, UpdateBefore, or by adding component Tag, to entities.

    However, I reached the point, Where sometimes loosing sync, with large number of entities, introducing some undesired behavior. That is, because number of chained systems sequence. I am disabling parallel jobs, where potential issues may occur, since many entities are dependent on other entities, or other complex structure of data.

    I try to avoid using on job completions, to avoid main thread lock.

    So, I decided try following approach, by replacing some jobs (disabling them for now), which are sequentially chained, and starting converting them into methods. Then call these method, from common system. I haven't complete fully this task yet (in progress), but so far it appears to work well.


    To give simplified example:
    Sub-System based architecture
    • CreateEntitySystem process of creation entity architecture.
    • DestroyEntitySystem process of destorying entity architecture.
    • CreateManyEntitiesSystem process of creating multiple entities, by adding appropriate tag to entity and calling CreateEntitySystem.
    • DestroyManyEntitiesSystem process of destroying multiple entities, by adding appropriate tag to entity and calling DestroyEntitySystem.

    New,
    Methods based architecture
    • CreateManyEntitiesSystem calls (in for loop) CreateEntity Method
    • DestroyManyEntitiesSystem (calls inf for loop) DestroyEntity Method

    I liked splitting processes into systems, since was nice, to call relevant process, from anywhere I wanted.
    Also, these were specifically decoupled from the other sub mechanics.

    Yet, I can achieve very similar result, with method based architecture, as long I can use burst and multi-threading.

    Main advantage I do introduce, by replacing systems into methods, is reduction of cascaded chains across multiple systems. That even with already filtered entities. Also, reducing tag switching via command buffer. These things don't happen every frame bear in mind, but may be in thousands at given frame.

    I still keep modular systems general architecture, but not splitting int sub systems, where sequence become critical.

    Eventually, I want "box in" this part of mechanics, in as few systems as possible. Then just call main control system from main game. So I don't think there is anything special here.


    Question

    There can be of course something, that I don't oversee, by replacing some systems, into methods and calling them from common system. So far it works, yet it became a little bit messy, until I test, confirm and cleanup.

    But is there anything, what you may think, which can potentially lead me into other troubles in the future, when expanding architecture? Or does it matter at all, if is one bigger system, rather than multiple smaller one?
     
    Last edited: Jun 21, 2019
  2. kstothert

    kstothert

    Joined:
    Dec 8, 2016
    Posts:
    68
    I come from a functional programming background so I have written all my systems with strict adherence to single responsibility principle. Is there a reason for systems that are thousands of lines long?
     
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    9,291
    Logic, multiple jobs in one system, comments and formatting. All adds up.
    But that is least relevant in this context.
    Systems do use methods in them already when appropriate. And there is Single Responsibility Principle in place already.
    For example I use one system which is calling same method multiple times, to check left, right, up etc., if you ask me. But I am not going to have each separate system for left, right, up ... checks, where their and rest of logic in particular job is highly dependent.
     
    Last edited: Jun 21, 2019
unityunity