Open arroz opened 1 year ago
Interesting: if I run the app directly from Finder, or if I launch it from Xcode after turning off the "Debug Executable" option, it runs at the expected speed. So this seems some kind of instrumentation Xcode is adding to the runtime (even if I build in Release mode) that slows down things considerably on the Go side (I don't see this kind of performance degradation on Swift code).
@arroz Indeed, it's possible that what you're seeing here is an effect of XCode's instrumented environment.
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.