How taxing are Logical ORs

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • I can't recall, and I don't remember if this was ever mentioned in any optimization threads.

    How expensive are ORs compared to normal comparisons? I have 6 events that have 8 logical ORs in them to compare the player's grid coordinates to an array, and I'd much rather just split them up into individual events if that would be more efficient.

    an example:

    -on loop
    -1,1,1 of array > 0
    OR (Logical)
    -on loop
    -1,1,2 of array > 0
    OR (Logical)
    -on loop
    -1,1,3 of array > 0

    I'll probably create a much more condensed method down the road, but it would still be useful to know

    Best person at writing incomprehensible posts. Edits are a regularity.

    Edited once, last by casleziro (January 2, 2015 at 5:52 AM).

  • Just from a basic test I did, it looks like Fusion's faster at processing two separate events versus one combined with OR (logical), but I don't know why that'd be. I'd have thought it'd be the other way around since Fusion should've stopped processing the OR event once the first case was true. Looking at this more, I'm positive that Fusion's doing something peculiar with the OR event but I can't tell you the reason it's taking so long to process it.

    Keep in mind that

    Code
    -on loop "Array"
    -[1,1,1] of Array > 0
    OR (logical)
    -on loop "Array"
    -[1,1,2] of Array > 0
    etc.


    is not the same as

    Code
    -on loop "Array"
    -[1,1,1] of Array > 0
    +do stuff
    
    
    -on loop "Array"
    -[1,1,2] of Array > 0
    +do stuff


    You will have to add a boolean under the "On loop" condition (this is the best place for it in terms of performance) to prevent (+do stuff) from running for each case where the conditions are true. The boolean shouldn't be that bad for performance but I don't know how it'll compare to OR. Running another benchmark with the boolean and the performance is about equal when you have only two events with the boolean. When you start adding more events with the boolean, performance will noticeably degrade in extreme situations.

    If performance is your goal, you'll want to create a group that contains all of the "On loop" events and then order from top-down the most likely to be true to the least likely to be true. On every event, deactivate the group. Have an "On loop" event placed above the group to activate it every event cycle. This is the same logic for ordering conditions in an event but taken to a larger scale. It's an ugly method but it'll be the fastest way to handle what you're talking about because you can't terminate a loop midway through it ("Stop loop" will only stop the loop after that event cycle has ended).

    A note: OR (logical) and OR (filtered) aren't used to distinguish anything in the conditions, only the actions. So if (+Do stuff) doesn't have to do with an object used in any of the conditions, OR (logical) and OR (filtered) can be used interchangeably.

  • I read through again and your input was really helpful. I'll definitely be separating the checks now and ordering them: I don't need specific conditions met, only one value set to determine collision so getting rid of the ORs won't be any problem. I had them ordered like that before too because I thought that Fusion might terminate after it had found the first true event (just like you did); it's really weird that it doesn't seem to!

    In any case, i'll keep the old OR method in a disabled group and then try it out after the groundwork is done later to see how it compares. Thanks again for the help :)

    Best person at writing incomprehensible posts. Edits are a regularity.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!