Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GoogleMaps on simulator in Xcode 9 uses over 100% of CPU when moving the map

So I've now converted my project to use Swift 4 in Xcode 9, and have started testing my app. It's a big app with four distinct tabs, and nearly everything is working as expected. One of the tabs is a map, using GoogleMaps. I have never had any trouble with it, but when built with Xcode 9 and shown in Simulator, it uses over 100% of CPU when moving the map, and it lags very much. Here is the debug navigator when running on a simulator. We do some custom drawing, but not 102% worth of drawing.

CPU usage

This only started happening after I updated to Xcode 9 and Swift 4. When debugging in Xcode 9 on an iPhone 7, 8 or X simulator, all with iOS 11, it goes just over 100% CPU, and it completely stops the UI from updating for about one second each time I try to move it. I start the drag-gesture, but the UI only updates once a second. Effectively giving me about 1fps.

However, when debugging in Xcode 9 on an iPhone 6 simulator with iOS 9, it gets up to ~90% when moving the map and not lagging nearly as much. I'm guessing I get about 20-30 fps here. (This might be the same fps I get in simulators on Xcode 8. Map has never been really smooth on simulator..)

When running on an actual device (iPhone 7, iOS 11), the CPU uses about 40% when constantly moving the map, and is working very smooth with no lags at all (60fps).

I also get this in the output as soon as I open the tab with the map, but I think it's irrelevant to this particular question:

Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState]
PID: *****, TID: *******, Thread name: com.google.Maps.LabelingBehavior, Queue name: com.apple.root.default-qos.overcommit, QoS: 21

This says that GoogleMapsAPI calls [UIApplication applicationState] on a background thread..

I am using the latest version of GoogleMaps: 2.4.0. As far as I know, this version may not support Xcode 9/Swift 4 etc, but I can't find anything about a new version.

like image 743
Sti Avatar asked Sep 15 '17 07:09

Sti


1 Answers

Update: This issue is fixed in Xcode 9.1 beta 2

There is a bug in OpenGLES.framework that causes it to skip loading the LLVM JIT and fall back to interpreting shaders. This has a severe performance impact on the Simulator since it is entirely software-rendered OpenGL (this includes CoreAnimation, SceneKit, etc).

edit: To clarify, the symptoms of this are exactly what you describe: 100% or greater CPU usage and <1fps rendering. This affects the Google Maps SDK and MapKit.

As a temporary workaround you can copy libCoreVMClient.dylib from Beta 3 into the Xcode 9 GM and performance should be restored to what it was previously. This must be done for each platform runtime separately.

For iOS this is located at: Xcode[-beta].app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/OpenGLES.framework/libCoreVMClient.dylib

For tvOS this is located at: Xcode[-beta].app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/tvOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/OpenGLES.framework/libCoreVMClient.dylib

For watchOS this is located at: Xcode[-beta].app/Contents/Developer/Platforms/WatchOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/watchOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/OpenGLES.framework/libCoreVMClient.dylib

like image 168
russbishop Avatar answered Nov 10 '22 05:11

russbishop