x/mobile: performance degradation by 2 orders of magnitude when running inside a Swift app #61203
Labels
mobile
Android, iOS, and x/mobile
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I'm trying to integrate some Go code with a Swift app. I noticed that code runs much slower when integrated on the Swift app than standalone on a pure Go environment. I did some experiments and came up with an interesting use case. Take this function:
I wrote a simple benchmark for this:
When running this from Visual Studio or directly from the command line using
go test -bench=.
, this function takes about 7ms to run. However, after building a framework for integrating with the Swift app (usinggomobile bind -target macos -ldflags="-s -w" -o hello.xcframework
), it takes, at best, ~700ms to run.If I remove the code that creates and appends to the slice, the execution time is similar on both environments, so I suspect this is something related with memory management.
I wondered if the
gomobile
command was building without optimizations or with any kind of debug code, but as far as I can understand (new Go user here), there's nothing like-O
here (Go builds are always as optimized as they can be?). So I'm a bit stuck on why this is so much slower when running from Swift. I'm ruling out any bridging code since the slowness happens entirely inside Go code, not pushing data back and forth between both worlds.What did you expect to see?
A similar execution time in both cases.
What did you see instead?
Running from Swift is ~100x slower.
The text was updated successfully, but these errors were encountered: