yy l
yy l

Reputation: 41

Go Mobile Performance: Regular CPU Usage Gaps on iOS

I'm encountering an interesting performance pattern when running a Go benchmark on iOS using gomobile. The CPU usage shows regular gaps of 30ms and 40ms between execution periods when monitored using Instruments.

Here's my minimal reproduction:

// benchmark/benchmark.go
package benchmark

func BasicOperations() {
    var sum float64
    
    for i := int32(1); i != 0; i++ {
        sum += 1
        sum *= 2
        sum -= 1
        sum /= 2
    }
}

I build the framework using:

gomobile bind -target=ios -o Benchmark.xcframework ./benchmark

When running this on an iOS device and profiling with Instruments, I observe:

Regular CPU usage patterns of about 30ms and 40ms duration (shown as blue bars in the CPU profile) Gaps between these CPU usage periods of varying lengths This pattern repeats consistently throughout execution

Instruments Screenshot Questions:

  1. Why does Go's runtime introduce these regular execution gaps on iOS?

  2. Is this expected behavior for Go on mobile platforms?

  3. How can I minimize these gaps to achieve more consistent CPU utilization?

Environment:

iOS 18.2 Go 1.21 gomobile latest version Testing on physical iPhone device

Upvotes: 3

Views: 39

Answers (0)

Related Questions