TLazyObjectPtr properties trigger checkSlow in FUniqueObjectGuid::GetOrCreateIDForObject when calling GetAllReferencers

There’s a couple things about our case that I wanted to mention while avoiding confidential details:

  • The use of TLazyObjectPtr is within a plugin and not our own code
  • The actual call to GetAllReferencers for us comes from FBlueprintSupport::FlushReinstancingQueue()

The issue stems from the implementation of GetAllReferencersIncludingWeak using a ParallelFor while TLazyObjectPtr’s serialization (used to find referencers) doesn’t support it in all cases.

That said, I think the checkSlow is asymptomatic. The ObjectGuid has been valid in all the instances I’ve seen and the call stems from a ParallelFor on the GameThread so the GuidAnnotation global should only be getting read from (i.e. The GameThread isn’t doing work that is writing to the GuidAnnotation).

The potential fixes I’ve considered are:

  • Force the ParallelFor GetAllReferencersIncludingWeak to always run SingleThreaded
  • Check if the weakptr is equal in FArchiveUObject::SerializeLazyObjectPtr before assigning it
  • Make the call threadsafe with RWLocks
  • Move the “checkSlow” into the block for the if (!ObjectGuid.IsValid()) as writes to GuidAnnotation are what we really care about

I’m going with the last fix for now.

Is there a separate fix you would recommend?

Steps to Reproduce
The repro project should have everything setup so just running the ReproMap should trigger the issue. Full repro steps are:

  • Have an Actor class with a UPROPERTY of type TLazyObjectPtr<T>
  • Make sure the TLazyObjectPtr points to a valid Actor
  • Make sure the WeakPtr within the TLazyObjectPtr is cached
  • Make sure GUObjectRegistrationComplete is true
  • Make sure checkSlows are enabled (i.e. Debug build)
  • Call FReferencerFinder::GetAllReferencers
    • I think any call will do however I did it from the object that the TLazyObjectPtr was pointing at
  • checkSlow(IsInGameThread()); in FUniqueObjectGuid::GetOrCreateIDForObject should trigger

This occurs on UE installed through launcher but the checkslow doesn’t trigger due to it being Development Editor.

Hi Matt, thanks for the repro. I didn’t see any attached repro project, but I managed to use your description to repro it in an internal project here. I’ve filed a ticket to get it fixed, so I don’t have a solution for you yet.

Steve

Appreciate you repro-ing it. Apologies about the project not being attached. Not quite sure what I did wrong but, on the bright side it spared you looking at some egregious log spam.