Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

saveInBackground taking minutes to complete and eating up CPU #982

Closed
tahoecoop opened this issue Jul 19, 2016 · 10 comments · May be fixed by #1589
Closed

saveInBackground taking minutes to complete and eating up CPU #982

tahoecoop opened this issue Jul 19, 2016 · 10 comments · May be fixed by #1589

Comments

@tahoecoop
Copy link

Hello! I'm using saveInBackgroundWithBlock: in multiple places to save several different subclasses of PFObject. Regardless of the object, as soon as I call this method the CPU starts running at close to 100%. Also the save doesn't go through for many seconds to several minutes. I see that the thread that is humming away shows Queue: PFSQLiteDatabase.synchronizationQueue (serial). This is the only thread that is doing anything while I wait for the save, the main thread is not doing anything.

I'm trying to figure out if the object I'm saving has another object its referencing that isn't there, and it gets stuck in a recursive loop? Or something in the framework that gets stuck somewhere? I've added the code for Parse debugging in the console but it's not giving me anything too useful. Any help is greatly appreciated, please advise if you require any other information. Thank you very much!

@gateway
Copy link

gateway commented Jul 21, 2016

I have noticed that as well.. @nlutsenko ?

@nlutsenko
Copy link
Contributor

Hey guys,
It would help tremendously if you could capture a stack trace or Instruments.app system trace for when it's happening.
If you have a lot of objects in Local Datastore, it could slow down, but is not expected to take minutes.

@parse-github-bot
Copy link

Thank you for your feedback. We prioritize issues that have clear and concise repro steps. Please see our Bug Reporting Guidelines about what information should be added to this issue.

Please try the latest SDK. Our release notes have details about what issues were fixed in each release.

In addition, you might find the following resources helpful:

@tahoecoop
Copy link
Author

Thanks for the help @nlutsenko. Here is what's running:

Thread 1Queue : com.apple.main-thread (serial)
#0  0x00000001108cdf72 in mach_msg_trap ()
#1  0x00000001108cd3b3 in mach_msg ()
#2  0x000000010de6f434 in __CFRunLoopServiceMachPort ()
#3  0x000000010de6e88f in __CFRunLoopRun ()
#4  0x000000010de6e0f8 in CFRunLoopRunSpecific ()
#5  0x0000000111accad2 in GSEventRunModal ()
#6  0x000000010e910f09 in UIApplicationMain ()
#7  0x000000010924ad42 in main at <removed>
#8  0x000000011058f92d in start ()
#9  0x000000011058f92d in start ()
Thread 2Queue : com.apple.libdispatch-manager (serial)
#0  0x00000001108d4ee2 in kevent64 ()
#1  0x000000011054a408 in _dispatch_mgr_invoke ()
#2  0x000000011054a1a2 in _dispatch_mgr_thread ()
Thread 9Queue : PFSQLiteDatabase.synchronizationQueue (serial)
#0  0x00000001108ae13d in _os_lock_handoff_trylock ()
#1  0x000000010d9dba56 in objc_object::sidetable_release(bool) ()
#2  0x00000001097acf2c in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#3  0x00000001097acfb0 in __82+[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:]_block_invoke ()
#4  0x000000010deb9ac5 in __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke ()
#5  0x000000010deb99cd in -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] ()
#6  0x00000001097acb73 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#7  0x00000001097acec6 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#8  0x00000001097aca27 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#9  0x00000001097acfb0 in __82+[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:]_block_invoke ()
#10 0x000000010deb9ac5 in __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke ()
#11 0x000000010deb99cd in -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] ()
#12 0x00000001097acb73 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#13 0x00000001097acec6 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#14 0x00000001097aca27 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#15 0x00000001097acfb0 in __82+[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:]_block_invoke ()
#16 0x000000010deb9ac5 in __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke ()
#17 0x000000010deb99a2 in -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] ()
#18 0x00000001097acb73 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#19 0x00000001097acec6 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#20 0x00000001097aca27 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#21 0x00000001097acfb0 in __82+[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:]_block_invoke ()
#22 0x000000010deb9ac5 in __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke ()
#23 0x000000010deb99cd in -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] ()
#24 0x00000001097acb73 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#25 0x00000001097acec6 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#26 0x00000001097aca27 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#27 0x00000001097acfb0 in __82+[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:]_block_invoke ()
#28 0x000000010deb9ac5 in __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke ()
#29 0x000000010deb99a2 in -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] ()
#30 0x00000001097acb73 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#31 0x00000001097acec6 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#32 0x00000001097aca27 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#33 0x00000001097acfb0 in __82+[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:]_block_invoke ()
#34 0x000000010deb9ac5 in __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke ()
#35 0x000000010deb99cd in -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] ()
#36 0x00000001097acb73 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#37 0x00000001097acec6 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#38 0x00000001097aca27 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#39 0x00000001097acfb0 in __82+[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:]_block_invoke ()
#40 0x000000010deb9ac5 in __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke ()
#41 0x000000010deb99a2 in -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] ()
#42 0x00000001097acb73 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#43 0x00000001097acec6 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#44 0x00000001097aca27 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#45 0x00000001097acfb0 in __82+[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:]_block_invoke ()
#46 0x000000010deb9ac5 in __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke ()
#47 0x000000010deb99cd in -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] ()
#48 0x00000001097acb73 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#49 0x00000001097acec6 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#50 0x00000001097aca27 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#51 0x00000001097acfb0 in __82+[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:]_block_invoke ()
#52 0x000000010deb9ac5 in __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke ()
#53 0x000000010deb99a2 in -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] ()
#54 0x00000001097acb73 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#55 0x00000001097acec6 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#56 0x00000001097aca27 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#57 0x00000001097acfb0 in __82+[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:]_block_invoke ()
#58 0x000000010deb9ac5 in __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke ()
#59 0x000000010deb99a2 in -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] ()
#60 0x00000001097acb73 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#61 0x00000001097acec6 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#62 0x00000001097aca27 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#63 0x00000001097acfb0 in __82+[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:]_block_invoke ()
#64 0x000000010deb9ac5 in __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke ()
#65 0x000000010deb99a2 in -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] ()
#66 0x00000001097acb73 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#67 0x00000001097acec6 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#68 0x00000001097aca27 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#69 0x00000001097acfb0 in __82+[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:]_block_invoke ()
#70 0x000000010deb9ac5 in __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke ()
#71 0x000000010deb99cd in -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] ()
#72 0x00000001097acb73 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#73 0x00000001097acec6 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#74 0x00000001097acfb0 in __82+[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:]_block_invoke ()
#75 0x000000010deb9ac5 in __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke ()
#76 0x000000010deb99cd in -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] ()
#77 0x00000001097acb73 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#78 0x00000001097acec6 in +[PFObject(Private) collectDirtyChildren:children:files:seen:seenNew:currentUser:] ()
#79 0x00000001097ad0f1 in +[PFObject(Private) collectDirtyChildren:children:files:currentUser:] ()
#80 0x00000001097ad8fd in +[PFObject(Private) _deepSaveAsyncChildrenOfObject:withCurrentUser:sessionToken:] ()
#81 0x00000001097afdd8 in -[PFObject(Private) _saveChildrenInBackgroundWithCurrentUser:sessionToken:] ()
#82 0x00000001097b50be in __31-[PFObject(Private) saveAsync:]_block_invoke.581 ()
#83 0x000000010984dc4b in __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke ()
#84 0x0000000109853c59 in __29+[BFExecutor defaultExecutor]_block_invoke_2 ()
#85 0x0000000109854197 in -[BFExecutor execute:] ()
#86 0x000000010984d822 in -[BFTask runContinuations] ()
#87 0x000000010984d384 in -[BFTask trySetError:] ()
#88 0x0000000109849e08 in -[BFTaskCompletionSource setError:] ()
#89 0x000000010984dedd in __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke_2 ()
#90 0x000000010984dc4b in __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke ()
#91 0x0000000109853c59 in __29+[BFExecutor defaultExecutor]_block_invoke_2 ()
#92 0x0000000109854197 in -[BFExecutor execute:] ()
#93 0x000000010984d822 in -[BFTask runContinuations] ()
#94 0x000000010984d384 in -[BFTask trySetError:] ()
#95 0x0000000109849e08 in -[BFTaskCompletionSource setError:] ()
#96 0x000000010984dedd in __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke_2 ()
#97 0x000000010984dd05 in __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke ()
#98 0x0000000109853c59 in __29+[BFExecutor defaultExecutor]_block_invoke_2 ()
#99 0x0000000109854197 in -[BFExecutor execute:] ()
#100    0x000000010984d822 in -[BFTask runContinuations] ()
#101    0x000000010984d23e in -[BFTask trySetResult:] ()
#102    0x0000000109849d5a in -[BFTaskCompletionSource setResult:] ()
#103    0x000000010984df2f in __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke_2 ()
#104    0x000000010984dc4b in __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke ()
#105    0x0000000109853c59 in __29+[BFExecutor defaultExecutor]_block_invoke_2 ()
#106    0x0000000109854197 in -[BFExecutor execute:] ()
#107    0x000000010984d822 in -[BFTask runContinuations] ()
#108    0x000000010984d23e in -[BFTask trySetResult:] ()
#109    0x0000000109849d5a in -[BFTaskCompletionSource setResult:] ()
#110    0x000000010984df2f in __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke_2 ()
#111    0x000000010984dc4b in __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke ()
#112    0x0000000109853c59 in __29+[BFExecutor defaultExecutor]_block_invoke_2 ()
#113    0x0000000109854197 in -[BFExecutor execute:] ()
#114    0x000000010984d822 in -[BFTask runContinuations] ()
#115    0x000000010984d23e in -[BFTask trySetResult:] ()
#116    0x0000000109849d5a in -[BFTaskCompletionSource setResult:] ()
#117    0x000000010984df2f in __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke_2 ()
#118    0x000000010984dd05 in __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke ()
#119    0x000000011055b3eb in _dispatch_client_callout ()
#120    0x000000011053fb74 in _dispatch_barrier_sync_f_slow ()
#121    0x00000001097f028c in PFThreadsafetySafeDispatchSync ()
#122    0x000000011053ad9d in _dispatch_call_block_and_release ()
#123    0x000000011055b3eb in _dispatch_client_callout ()
#124    0x0000000110543b2f in _dispatch_root_queue_drain ()
#125    0x0000000110543405 in _dispatch_worker_thread3 ()
#126    0x00000001108984de in _pthread_wqthread ()
#127    0x0000000110896341 in start_wqthread ()
Enqueued from PFSQLiteDatabase.synchronizationQueue (Thread 14)Queue : PFSQLiteDatabase.synchronizationQueue (serial)
#0  0x000000011053ed12 in dispatch_async ()
#1  0x00000001098227b1 in __33-[PFSQLiteDatabase initWithPath:]_block_invoke ()
#2  0x0000000109854197 in -[BFExecutor execute:] ()
#3  0x000000010984da94 in -[BFTask continueWithExecutor:block:cancellationToken:] ()
#4  0x000000010984d923 in -[BFTask continueWithExecutor:withBlock:] ()
#5  0x000000010984d0d6 in +[BFTask taskFromExecutor:withBlock:] ()
#6  0x0000000109822cdf in -[PFSQLiteDatabase closeAsync] ()
#7  0x000000010984dc4b in __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke ()
#8  0x0000000109853c59 in __29+[BFExecutor defaultExecutor]_block_invoke_2 ()
#9  0x0000000109854197 in -[BFExecutor execute:] ()
#10 0x000000010984da94 in -[BFTask continueWithExecutor:block:cancellationToken:] ()
#11 0x000000010984e0c9 in -[BFTask continueWithBlock:] ()
#12 0x00000001098220c4 in __58-[PFOfflineStore _performDatabaseOperationAsyncWithBlock:]_block_invoke ()
#13 0x000000010984dc4b in __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke ()
#14 0x0000000109853c59 in __29+[BFExecutor defaultExecutor]_block_invoke_2 ()
#15 0x0000000109854197 in -[BFExecutor execute:] ()
#16 0x000000010984d822 in -[BFTask runContinuations] ()
#17 0x000000010984d23e in -[BFTask trySetResult:] ()
#18 0x0000000109849fd5 in -[BFTaskCompletionSource trySetResult:] ()
#19 0x00000001097bead8 in __56-[PFSQLiteDatabaseController openDatabaseWithNameAsync:]_block_invoke_2 ()
#20 0x000000010984dc4b in __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke ()
#21 0x0000000109853c59 in __29+[BFExecutor defaultExecutor]_block_invoke_2 ()
#22 0x0000000109854197 in -[BFExecutor execute:] ()
#23 0x000000010984d822 in -[BFTask runContinuations] ()
#24 0x000000010984d23e in -[BFTask trySetResult:] ()
#25 0x0000000109849d5a in -[BFTaskCompletionSource setResult:] ()
#26 0x000000010984dd1b in __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke ()
#27 0x000000011055b3eb in _dispatch_client_callout ()
#28 0x000000011053fef5 in _dispatch_barrier_sync_f_invoke ()
#29 0x00000001097f028c in PFThreadsafetySafeDispatchSync ()
#30 0x000000011053ad9d in _dispatch_call_block_and_release ()
#31 0x000000011055b3eb in _dispatch_client_callout ()
#32 0x0000000110543b2f in _dispatch_root_queue_drain ()
#33 0x0000000110543405 in _dispatch_worker_thread3 ()
#34 0x00000001108984de in _pthread_wqthread ()
#35 0x0000000110896341 in start_wqthread ()
Enqueued from com.apple.root.default-qos (Thread 14)Queue : com.apple.root.default-qos (concurrent)
#0  0x000000011053ed12 in dispatch_async ()
#1  0x00000001098227b1 in __33-[PFSQLiteDatabase initWithPath:]_block_invoke ()
#2  0x0000000109854197 in -[BFExecutor execute:] ()
#3  0x000000010984da94 in -[BFTask continueWithExecutor:block:cancellationToken:] ()
#4  0x000000010984d923 in -[BFTask continueWithExecutor:withBlock:] ()
#5  0x000000010984d0d6 in +[BFTask taskFromExecutor:withBlock:] ()
#6  0x0000000109822a1e in -[PFSQLiteDatabase openAsync] ()
#7  0x00000001097be967 in __56-[PFSQLiteDatabaseController openDatabaseWithNameAsync:]_block_invoke ()
#8  0x000000010984dc4b in __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke ()
#9  0x000000011053ad9d in _dispatch_call_block_and_release ()
#10 0x000000011055b3eb in _dispatch_client_callout ()
#11 0x0000000110543b2f in _dispatch_root_queue_drain ()
#12 0x0000000110543405 in _dispatch_worker_thread3 ()
#13 0x00000001108984de in _pthread_wqthread ()
#14 0x0000000110896341 in start_wqthread ()
Enqueued from com.parse.asynctaskqueue.sync (Thread 9)Queue : com.parse.asynctaskqueue.sync (serial)
#0  0x000000011053ed12 in dispatch_async ()
#1  0x0000000109854197 in -[BFExecutor execute:] ()
#2  0x000000010984da94 in -[BFTask continueWithExecutor:block:cancellationToken:] ()
#3  0x000000010984d923 in -[BFTask continueWithExecutor:withBlock:] ()
#4  0x00000001097fa11a in -[BFTask(Private) continueAsyncWithBlock:] ()
#5  0x000000010978f4fb in __28-[PFAsyncTaskQueue enqueue:]_block_invoke ()
#6  0x000000011053ad9d in _dispatch_call_block_and_release ()
#7  0x000000011055b3eb in _dispatch_client_callout ()
#8  0x000000011054182c in _dispatch_queue_drain ()
#9  0x0000000110540d4d in _dispatch_queue_invoke ()
#10 0x0000000110543996 in _dispatch_root_queue_drain ()
#11 0x0000000110543405 in _dispatch_worker_thread3 ()
#12 0x00000001108984de in _pthread_wqthread ()
#13 0x0000000110896341 in start_wqthread ()
Enqueued from com.apple.main-thread (Thread 1)Queue : com.apple.main-thread (serial)
#0  0x0000000110544046 in _dispatch_barrier_async_f_slow ()
#1  0x000000010978f46c in -[PFAsyncTaskQueue enqueue:] ()
#2  0x00000001097dbb84 in -[PFCurrentUserController getCurrentUserAsyncWithOptions:] ()
#3  0x00000001097b4cea in -[PFObject(Private) saveAsync:] ()
#4  0x000000010981216c in -[PFTaskQueue enqueue:] ()
#5  0x00000001097b815c in -[PFObject saveInBackground] ()
#6  0x00000001097b81f8 in -[PFObject saveInBackgroundWithBlock:] ()
#7  0x00000001090722c0 in static Utils.incrementUserPointsByX(Int, activityType : String) -> () at <removed>
#8  0x000000010923186e in CheckInViewController.onCheckInButtonPressed(UIButton) -> () at <removed>
#9  0x00000001092337da in @objc CheckInViewController.onCheckInButtonPressed(UIButton) -> () ()
#10 0x000000010e912a8d in -[UIApplication sendAction:to:from:forEvent:] ()
#11 0x000000010ea85e67 in -[UIControl sendAction:to:forEvent:] ()
#12 0x000000010ea86143 in -[UIControl _sendActionsForEvents:withEvent:] ()
#13 0x000000010ea85263 in -[UIControl touchesEnded:withEvent:] ()
#14 0x000000010e98599f in -[UIWindow _sendTouchesForEvent:] ()
#15 0x000000010e9866d4 in -[UIWindow sendEvent:] ()
#16 0x000000010e931dc6 in -[UIApplication sendEvent:] ()
#17 0x000000010e90b553 in _UIApplicationHandleEventQueue ()
#18 0x000000010de79301 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#19 0x000000010de6f22c in __CFRunLoopDoSources0 ()
#20 0x000000010de6e6e3 in __CFRunLoopRun ()
#21 0x000000010de6e0f8 in CFRunLoopRunSpecific ()
#22 0x0000000111accad2 in GSEventRunModal ()
#23 0x000000010e910f09 in UIApplicationMain ()
#24 0x000000010924ad42 in main at <removed>
#25 0x000000011058f92d in start ()
Thread 11#0 0x00000001108d45e2 in __workq_kernreturn ()
#1  0x0000000110898578 in _pthread_wqthread ()
#2  0x0000000110896341 in start_wqthread ()
Thread 12#0 0x00000001108d45e2 in __workq_kernreturn ()
#1  0x0000000110898578 in _pthread_wqthread ()
#2  0x0000000110896341 in start_wqthread ()
Thread 14#0 0x00000001108d45e2 in __workq_kernreturn ()
#1  0x0000000110898578 in _pthread_wqthread ()
#2  0x0000000110896341 in start_wqthread ()
Thread 16#0 0x00000001108cdf72 in mach_msg_trap ()
#1  0x00000001108cd3b3 in mach_msg ()
#2  0x000000010de6f434 in __CFRunLoopServiceMachPort ()
#3  0x000000010de6e88f in __CFRunLoopRun ()
#4  0x000000010de6e0f8 in CFRunLoopRunSpecific ()
#5  0x000000010cd81d24 in +[NSURLConnection(Loader) _resourceLoadLoop:] ()
#6  0x000000010d65012b in __NSThread__start__ ()
#7  0x000000011089899d in _pthread_body ()
#8  0x000000011089891a in _pthread_start ()
#9  0x0000000110896351 in thread_start ()
Thread 17#0 0x00000001108d407a in __select ()
#1  0x000000010deb45ea in __CFSocketManager ()
#2  0x000000011089899d in _pthread_body ()
#3  0x000000011089891a in _pthread_start ()
#4  0x0000000110896351 in thread_start ()

@nlutsenko
Copy link
Contributor

@tahoecoop, any chance you can showcase how does your schema look like?
I am curious on why does it need to parse the entire tree of objects...

@tahoecoop
Copy link
Author

Thanks for the reply @nlutsenko, what do you mean that it's parsing the entire tree of objects? Not sure what other objects it would need to parse at this point to create this CheckIn. This behavior seems to happen regardless of the PFObject subclass I'm trying to save. My custom PFObjects do have pointers to other of my custom PFObjects. Let me know if there's anything specific you're thinking about and I can get you more info. Thanks again!

      let checkIn = CheckIn()
      checkIn.user = User.currentUser()
      checkIn.placeName = selectedPlace.name
      checkIn.geoPoint =  PFGeoPoint(latitude: lat, longitude: long)
      checkIn.locationID = selectedPlace.locationID

      if commentTextView.text != "" {
         checkIn.comment = commentTextView.text
      }

      if selectedPlace.facebookID != nil {
         checkIn.facebookID = selectedPlace.facebookID!
      }

         checkIn.saveInBackgroundWithBlock({ (success, error) in

            if success {
                  ...
            } else {
                   ...
            }
         })

@tahoecoop tahoecoop reopened this Jul 21, 2016
@gateway
Copy link

gateway commented Jul 22, 2016

Any updates to this, seeing similar lag times..

@gateway
Copy link

gateway commented Jul 26, 2016

This is what the cpu's look like and 2 threads are just pegged for quite some time..

image

@tahoecoop
Copy link
Author

After doing some more research, it appears that our User object may be causing the lock. One of the properties on my PFUser subclass is an array of other users (friends of this user in the app). I save a pointer to the User.currentUser() as part of all my other objects, it looks likes it's iterating through the friend list, which in turn keeps iterating through their friend list.

Also, when I log into my app as an email user (without a friend list attached to user object), all saves execute quickly and smooth, so it appears this is probably it.

Do you have any suggestions on saving a list of users to my User so the saveInBackground isn't put into this deadlock? Here is the schema for my user object, thanks for the assistance!!

   @NSManaged var fbName: String?
   @NSManaged var facebookID: String?
   @NSManaged var fbLocale: String?
   @NSManaged var fbTimezone: NSNumber?
   @NSManaged var fbGender: String?
   @NSManaged var fbEmail: String?
   @NSManaged var fbAge: NSNumber?
   @NSManaged var profileImage: PFFile?
   @NSManaged var state: String?
   @NSManaged var birthday: String?
   @NSManaged var friendsUsingTheApp:[User]?
   @NSManaged var newFriendsToShowUserInFeed:[User]?
   @NSManaged var friendRelationships:[Relationship]?
   @NSManaged var isMasterUser: NSNumber?
   @NSManaged var displayName: String?

@gateway
Copy link

gateway commented Jul 26, 2016

We found out this issue because we decided to do some logging on PFObject.m in this block of code

/**
 Finds all of the objects that are reachable from child, including child itself,
 and adds them to the given mutable array.  It traverses arrays and json objects.
 @param node  An kind object to search for children.
 @param dirtyChildren  The array to collect the result into.
 @param seen  The set of all objects that have already been seen.
 @param seenNew  The set of new objects that have already been seen since the
 last existing object.
 */
+ (void)collectDirtyChildren:(id)node
                    children:(NSMutableSet *)dirtyChildren
                       files:(NSMutableSet *)dirtyFiles
                        seen:(NSSet *)seen
                     seenNew:(NSSet *)seenNew
                 currentUser:(PFUser *)currentUser {
    if ([node isKindOfClass:[NSArray class]]) {
        for (id elem in node) {
            @autoreleasepool {
                [self collectDirtyChildren:elem
                                  children:dirtyChildren
                                     files:dirtyFiles
                                      seen:seen
                                   seenNew:seenNew
                               currentUser:currentUser];
            }
        }
    } else if ([node isKindOfClass:[NSDictionary class]]) {
        [node enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
            NSLog(@"%@", key);  // Goes crazy in the else function.. 
            NSLog(@"%@", obj);
            [self collectDirtyChildren:obj
                              children:dirtyChildren
                                 files:dirtyFiles
                                  seen:seen
                               seenNew:seenNew
                           currentUser:currentUser];
        }];

So we built a loop that went crazy since friends of the app is pointer to each friend, which intern has its own pointers to their friends and so on.

Can we build up an object to just save the columns for our comment text w/o it having to go though all this reference lookup, or how would you suggest we tackle this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants