Search Unity

Does burst have any problems with using C# properties in struct datatypes?

Discussion in 'Burst' started by SurprisedPikachu, May 31, 2021.

  1. SurprisedPikachu

    SurprisedPikachu

    Joined:
    Mar 12, 2020
    Posts:
    84
    Is there going to be a performance difference when using:
    Code (CSharp):
    1. public struct MyDataType { public int Value; }
    vs
    Code (CSharp):
    1. public struct MyDataType { public int Value {get;set;} }
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    Preoprties are methods, not fields. Auto-properties are tightly-coupled methods and fields. Burst may optimize out the methods, but there's no guarantee. I wouldn't use properties unless you need the method side-effects or you need to make the setter internal or private (which Burst will almost certainly optimize for you).
     
  3. SamOld

    SamOld

    Joined:
    Aug 17, 2018
    Posts:
    333
    Have you ever seen it fail to optimise an auto property? I would expect that the trivial body is guaranteed to be inlined, but I haven't checked that assumption in detail. I do sometimes use auto properties with Burst as a carry over of normal C# habits and I've never noticed it being a problem, although you have significantly more Burst experience than I do.
     
  4. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    If by "optimize" you mean "inline", it has always been optimized whenever I care to check. But usually my code that touches auto properties isn't the performance bottleneck, so I don't usually check.

    Now auto-vectorization is a different story, one with suspects and an unknown culprit.