a7medev / react-native-ml-kit

React Native On-Device Machine Learning w/ Google ML Kit
MIT License
342 stars 55 forks source link

Performance degradation in iOS simulator when using MLKit #45

Open danielrhodes opened 8 months ago

danielrhodes commented 8 months ago

What happened?

This library was easy to install and use, but I noticed that I got a warning that I needed to use Rosetta in order to be compatible with other libraries.

Screenshot 2023-10-31 at 16 46 21

Additionally, I noticed there was a slow down in the app when using Rosetta in the Simulator, which makes some sense. I traced the issue back to Google's MLKit Podspec, which is excluding arm64 simulator builds, which means Xcode is forced to use x386 and then use Rosetta for the other libraries.

https://github.com/CocoaPods/Specs/blob/master/Specs/b/e/b/GoogleMLKit/4.0.0/GoogleMLKit.podspec.json#L18

Since the MLKit Cocoapod would obviously have arm64 support, you can force Cocoapods to not switch the architecture like so:

post_install do |installer|
    # put this at the end of this block
    installer.pods_project.build_configurations.each do |config|
       config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
    end
end

This worked - the app built for the simulator without forcing me to use Rosetta. However, the performance degradation still persisted. An example of this is that the frame rate is seriously slow on a table when scrolling.

The production build does not appear to have this problem, or at least it is far less so. I'm not sure how to explain this!

Version

latest

Which ML Kit packages do you use?

What platforms are you seeing this issue on?

System Information

System:
  OS: macOS 14.1
  CPU: (10) arm64 Apple M1 Max
  Memory: 1.01 GB / 64.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.8.0
    path: /opt/homebrew/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.yarn/bin/yarn
  npm:
    version: 10.1.0
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2023.09.25.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.11.3
    path: /Users/<redacted>/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.0
      - iOS 17.0
      - macOS 14.0
      - tvOS 17.0
      - watchOS 10.0
  Android SDK: Not Found
IDEs:
  Android Studio: Not Found
  Xcode:
    version: 15.0.1/15A507
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 18.0.1
    path: /usr/bin/javac
  Ruby:
    version: 2.7.6
    path: /Users/<redacted>/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.6
    wanted: ^0.72.6
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Steps to Reproduce

Explained above.