rive-app / rive-ios

iOS runtime for Rive
MIT License
462 stars 53 forks source link

Rive causing an app UI hang alert #289

Open somero opened 5 months ago

somero commented 5 months ago

Description

Our app keep on sending alerts about ui hangs, which seems to be related to Rive. We're using Sentry's app hangs alert, and wanted to check this with you, as this alert when raised in our code, exposed misuse of main thread, that was pretty easy to resolve (heavy logic that happened on main thread by mistake).

This is how our main thread's call stack looks like:

libsystem_kernel    0x1e93ac1d8  mach_msg2_trap
  libsystem_kernel    0x1e93abf6c  mach_msg2_internal
  libsystem_kernel    0x1e93abe84  mach_msg_overwrite
  libsystem_kernel    0x1e93abcc4  mach_msg
  libdispatch         0x1a9e77efc  _dispatch_mach_send_and_wait_for_reply
  libdispatch         0x1a9e7829c  dispatch_mach_send_with_result_and_wait_for_reply
  libxpc              0x20b94f6d0  xpc_connection_send_message_with_reply_sync
  Metal               0x1a1ac01f8  XPCCompilerConnection::BuildRequestInternal
  Metal               0x1a1abfd68  XPCCompilerConnection::BuildRequest
  libdispatch         0x1a9e5d2fc  _dispatch_client_callout
  libdispatch         0x1a9e6c6b0  _dispatch_lane_barrier_sync_invoke_and_complete
  Metal               0x1a1acacec  XPCCompilerConnection::BuildRequest
  Metal               0x1a1acaba0  MTLCompilerConnectionManagerPrivate::buildRequest
  Metal               0x1a1b9dc60  MTLLibraryBuilder::initLibraryContainerWithRequestData
  Metal               0x1a1b9e468  MTLLibraryBuilder::newLibraryWithRequestDataAndHash
  Metal               0x1a1b9fb24  MTLLibraryBuilder::newLibraryWithSource
  Metal               0x1a1b64858  -[_MTLDevice newLibraryWithSource:options:error:]
  AGXMetalA14         0x23adad4f8  <redacted>
  RiveRuntime         0x103676c8c  GrCompileMtlShaderLibrary
  RiveRuntime         0x10366e018  GrMtlPipelineStateBuilder::finalize
  RiveRuntime         0x10366c8e4  GrMtlPipelineStateBuilder::CreatePipelineState
  RiveRuntime         0x1036721b4  GrMtlResourceProvider::PipelineStateCache::onRefPipelineState
  RiveRuntime         0x1036676dc  GrMtlOpsRenderPass::onBindPipeline
  RiveRuntime         0x1035541d8  GrOpsRenderPass::bindPipeline
  RiveRuntime         0x1035de5ac  (anonymous namespace)::AAHairlineOp::onExecute
  RiveRuntime         0x103608444  skgpu::v1::OpsTask::onExecute
  RiveRuntime         0x103547234  GrDrawingManager::flush
  RiveRuntime         0x103548004  GrDrawingManager::flushSurfaces
  RiveRuntime         0x103540e74  GrDirectContextPriv::flushSurfaces
  RiveRuntime         0x1035d35b8  SkSurface_Gpu::onFlush
  RiveRuntime         0x1035d5c64  SkSurface::flushAndSubmit
  RiveRuntime         0x1033da748  -[SkiaContext endFrame]
  RiveRuntime         0x1033d90b4  -[RiveRendererView drawRect:]
  MetalKit            0x212001468  -[MTKView draw]
  QuartzCore          0x1a350be50  CA::Layer::layout_and_display_if_needed
  QuartzCore          0x1a3512274  CA::Context::commit_transaction
  QuartzCore          0x1a350b570  CA::Transaction::commit
  QuartzCore          0x1a350b218  CA::Transaction::flush_as_runloop_observer
  UIKitCore           0x1a416e970  _UIApplicationFlushCATransaction
  UIKitCore           0x1a416e488  _UIUpdateSequenceRun
  UIKitCore           0x1a416db78  schedulerStepScheduledMainSection
  UIKitCore           0x1a416dc34  runloopSourceCallback
  CoreFoundation      0x1a1ed7318  __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
  CoreFoundation      0x1a1ed6594  __CFRunLoopDoSource0
  CoreFoundation      0x1a1ed4d48  __CFRunLoopDoSources0
  CoreFoundation      0x1a1ed3a84  __CFRunLoopRun
  CoreFoundation      0x1a1ed3664  CFRunLoopRunSpecific
  GraphicsServices    0x1e529e5e8  GSEventRunModal
  UIKitCore           0x1a42f02b0  -[UIApplication _run]
  UIKitCore           0x1a42ef8ec  UIApplicationMain
  SwiftUI             0x1a6cf20f8  OUTLINED_FUNCTION_31
  SwiftUI             0x1a6cf1f3c  OUTLINED_FUNCTION_31
  SwiftUI             0x1a6963864  OUTLINED_FUNCTION_26
  GoodOnes            0x100d0c7ec  GoodOnesApp.$main (GoodOnesApp.swift)
  GoodOnes            0x100d0c7ec  main (GoodOnesApp.swift)

This doesn't happen all the time, but just for some cases in production. My ask here - is there some kind of initialization logic / some other heavy lift, that shouldn't happen on MainThread in this call stack?

Expected behavior

No UI hangs :]

Additional context

More info about Sentry's app hang mechanism can be found here.

SleepiestAdam commented 5 months ago

+1 - we're also seeing this, getting 250-600ms hangs that we've narrowed down to sections of the app containing multiple rive animations.

psbss commented 2 weeks ago

same 👍