flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[Update] Cloud Firestore Xcode Build Times

Open Salakar opened this issue 6 years ago â€ĸ 103 comments

Hey everyone 👋

One of the key issues we wanted to look into providing a solution for was https://github.com/FirebaseExtended/flutterfire/issues/349 - improving build times for Xcode when using Firestore.

I'm happy to say we now have something for you to try (please provide feedback) that should significantly improve your build times;

Mac mini (2018) 6 cores:

Before:    ~ 240s
After:     ~  45s

GitHub Action CI 2 cores:

Before:    ~ 551s
After:     ~ 174s

Why is it slow?

Currently the Firestore iOS SDK depends on some 500k lines of mostly C++ code (from dependencies such as gRPC), which when compiling as part of your Xcode build can take a long time - even more so in CI environments.

How can we speed it up?

The biggest win to improving build times would be to not have to compile all that C++ code. The way to do that would be to consume precompiled binaries, in the new XCFramework bundle type introduced to Xcode last year, luckily as part of the Firebase iOS SDK release process these bundles are generated and published in a zip containing all Firebase SDKs.

To help you consume these quicker with the least amount of changes to your codebase we've created invertase/firestore-ios-sdk-frameworks - a repository that provides a drop in replacement podspec for Firestore that consumes the precompiled binaries instead, without you needing to download 3gb of SDKs and manually extract out the Firestore SDKs from the rest of the SDKs in the zip.

⚡ Setup ⚡

To integrate, you just need to add 1 line to your ios/Podfile inside your Flutter project;

pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '7.4.0'

Add this line inside your target 'Runner' do block in your Podfile, e.g.:

# ...
target 'Runner' do
  pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '7.4.0'

# ...
end

No changes to the FlutterFire packages were required. See #4698 for a full example of integrating with automatic versioning based on what firebase_core uses.

Why not ship the binaries with the pub packages?

This would add ~200mb to every release. Whereas via a custom pod this is only ever downloaded once on your machine per Firebase iOS SDK version.


For more information on the pod and versioning please see the invertase/firestore-ios-sdk-frameworks repository.


âš ī¸ Note: if you were previously caching iOS builds on CI you may now find that when using precompiled binaries that caching is no longer required and it may actually slow down your build times by several minutes. See this comment below for more; https://github.com/FirebaseExtended/flutterfire/issues/2751#issuecomment-643190500


✨ Please let me know if this has helped you, and I would love to see some before and after timings if you feel like sharing ✨

Salakar avatar Jun 12 '20 04:06 Salakar

This actually works for more than flutter, for react-native-firebase or anyone that integrates the firestore pod it works, I know this because my creaky old 4 core mbp takes about 5mins less to compile and get the app running. 1 line! Thank you.

mikehardy avatar Jun 12 '20 04:06 mikehardy

This actually works for more than flutter, for react-native-firebase or anyone that integrates the firestore pod it works, I know this because my creaky old 4 core mbp takes about 5mins less to compile and get the app running. 1 line! Thank you.

Yep, works for anyone using Firestore on iOS - no matter the framework 🎉

Salakar avatar Jun 12 '20 04:06 Salakar

Thanks for the tip. However when I try to implement it, I get :

 [!] CocoaPods could not find compatible versions for pod "FirebaseFirestore":
      In snapshot (Podfile.lock):
        FirebaseFirestore (= 1.11.2, ~> 1.11.2)
      In Podfile:
        FirebaseFirestore (from `https://github.com/invertase/firestore-ios-sdk-frameworks.git`, tag `6.26.0`)
    None of your spec sources contain a spec satisfying the dependencies: `FirebaseFirestore (from `https://github.com/invertase/firestore-ios-sdk-frameworks.git`, tag `6.26.0`), FirebaseFirestore (= 1.11.2, ~> 1.11.2)`.
    You have either:
     * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
     * mistyped the name or version.
     * not added the source repo that hosts the Podspec to your Podfile.

I tried to pod update, but with no luck

Any idea ?

galvin59 avatar Jun 12 '20 06:06 galvin59

@jsoms try removing your Podfile.lock and trying again.

Ehesp avatar Jun 12 '20 06:06 Ehesp

I started simple tests on codemagic and there's at least few minutes decrease in iOS build time. Unfortunately cache upload caused the total build to be still rather long.

I'm going to update this table with next results.

Flutter stable 1.17.3 Xcode 11.5

Id Precompiled binaries Cache machine cloud_firestore version Firestore Fetch Installing dep iOS pod install Xcode build Total
40 đŸšĢ (no_cache) no mini 0.13.4+2 6.23.0 0:00:04 0:01:43 0:30:50 278 793 0:49:34
41 đŸšĢ (no_cache) no mini 0.13.4+2 6.23.0 0:00:04 0:01:09 0:26:10 212 755 0:45:10
251 đŸšĢ (cache) yes mini 0.13.4+2 6.23.0 0:03:10 0:01:01 0:27:43 291 604 0:48:20
253 ✅ (cache) yes mini 0.13.4+2 6.23.0 0:04:28 0:01:27 0:16:17 193 402 0:42:00
254 ✅ (cache) yes mini 0.13.4+2 6.23.0 0:02:26 0:00:56 0:15:00 195 376 0:36:30
255 ✅ (cache) yes mini 0.13.4+2 6.23.0 0:04:01 0:01:17 0:14:55 201 424 0:41:33
1_no_cache ✅ (no_cache) no mini 0.13.4+2 6.23.0 0:00:05 0:01:09 0:13:29 165 404 0:25:52
2_no_cache ✅ (no_cache) no mini 0.13.4+2 6.23.0 0:00:18 0:01:27 0:14:43 169 478 0:26:06
3_no_cache ✅ (no_cache) no mini 0.13.4+2 6.23.0 00:00:07 00:02:15 00:17:04 220 463 00:30:20
4_no_cache_pro ✅ (no_cache_pro) no pro 0.13.4+2 6.23.0 00:00:02 00:00:57 00:09:27 141 273 00:17:21
5_no_cache ✅ (no_cache) no mini 0.13.4+2 6.23.0 00:00:05 00:01:11 00:12:39 136 366 00:23:52

image

1_no_cache is completely new workflow on codemagic without any cache but with precompiled binaries!

pro means that it was run on Mac Pro

Important remark when using cache the Android build is significantly shorter (eg 15 vs 9 min). Also cache usually takes 2 min to download and 4-6 min to create and upload.

orestesgaolin avatar Jun 12 '20 10:06 orestesgaolin

@orestesgaolin what's it like without uploading build caches?

Salakar avatar Jun 12 '20 13:06 Salakar

@Salakar I updated my comment above and it's so surprising to see that without any cache (i.e. completely clean build on new workflow) the build time dropped dramatically to about 13 min. I'm gonna run it again without any cache

orestesgaolin avatar Jun 12 '20 14:06 orestesgaolin

@Salakar second build without cache was a bit longer, so it seems that it doesn't have significant effect (thus it may be completely unnecessary to use). I will be collecting data in subsequent builds and maybe we can then draw some conclusions out of it

orestesgaolin avatar Jun 12 '20 15:06 orestesgaolin

Note using xcframeworks requires CocoaPods 1.9.0 or higher. Flutter currently requires a minimum of 1.6.

@Salakar Created issue to add cocoapods_version to the podspec. https://github.com/invertase/firestore-ios-sdk-frameworks/issues/1.

jmagman avatar Jun 12 '20 17:06 jmagman

Could you help me?

  • I run 'pod deintegrate';
  • Deleted Pofile.lock
  • Run 'pod install'

And I got this: [!] CocoaPods could not find compatible versions for pod "FirebaseFirestore": In Podfile: FirebaseFirestore (from https://github.com/invertase/firestore-ios-sdk-frameworks.git, tag 6.26.0)

cloud_firestore (from `.symlinks/plugins/cloud_firestore/ios`) was resolved to 0.0.1, which depends on
  Firebase/Firestore (~> 6.0) was resolved to 6.0.0, which depends on
    FirebaseFirestore (~> 1.3.0)

What must I do? Thank you.

ElaineSchwner avatar Jun 12 '20 19:06 ElaineSchwner

@ElaineSchwner I solved a similar problem with pod repo update as per @jsoms ' comment.

red42 avatar Jun 12 '20 19:06 red42

pod repo update

Solved ! Thank you!

ElaineSchwner avatar Jun 12 '20 19:06 ElaineSchwner

It worked well. Thanks a lot đŸ›Šī¸ 😄

mafreud avatar Jun 14 '20 01:06 mafreud

This didn't work for me. I tried pod install, pod update... See this:

Xcode build done.
Could not build the application for the simulator.
Error launching application on iPhone 11.

RaviKavaiya avatar Jun 16 '20 07:06 RaviKavaiya

Hi @RaviKavaiya we'll need more information to help on that one. It looks like the XCode build succeeded but then fails when the app is launched - what are the errors?

Ehesp avatar Jun 16 '20 13:06 Ehesp

@Ehesp I tried running with flutter run -v. Couldn't find anything. Will give another shot later and will tell you..

Thanks

RaviKavaiya avatar Jun 16 '20 13:06 RaviKavaiya

Build timings on my MacBook Pro (2018) 4 cores:

Before:   ~ 272s
After:    ~ 122s

A very nice speed improvement, thank you!

How can we tell which version of the iOS SDK the cloud_firestore package uses, so we can keep the tag up to date in our Podfile? I hope that will be part of the package's release notes going forward?

andre-arsenault avatar Jun 17 '20 10:06 andre-arsenault

ld: library not found for -lBoringSSL-GRPC

I've raised an issue against the firestore-ios-sdk-frameworks library - referencing it here in case it helps someone else...

ghost avatar Jun 17 '20 23:06 ghost

On an old Macbook Pro ( 2011 - 2 cores - i7 )

before ~ 15 minutes after ~ 9 minutes

Thanks!

farukozsoy avatar Jun 19 '20 14:06 farukozsoy

Is there also a workaround for Flutter macOS?

nilsreichardt avatar Jun 23 '20 09:06 nilsreichardt