Making flutter builds faster

build-cache
flutter
#1

Hi,

I’ve set up a flutter build and all is working fine for both iOS and Android. I was hoping to make the build a bit faster by leveraging caching. However, my attempts so far have just slowed things down. That’s because despite caching, the steps I was hoping would be faster (such as installing flutter) are still the same. That is, they’re not using the cache to avoid the need to re-install.

Is there any guidance on setting up flutter with Bitrise in such a way as to avoid the ~3 mins required to simply install flutter on every build?

For the record, I tried caching these paths:

  • /Users/vagrant/flutter/
  • /Users/vagrant/.pub-cache/
  • /usr/local/Cellar/
  • /Users/vagrant/Library/Caches/Homebrew/

However, that was far too expensive (~4GB) and was recreating the cache every time due to irrelevant file changes. I also tried toning it right down to just:

  • /Users/vagrant/flutter/

The cache was still approaching 1GB and it would have been faster, except flutter still insisted on running a full install. My install script for flutter is:

    - script:
        title: Install flutter
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            cd ..
            git clone -b alpha https://github.com/flutter/flutter.git
            export PATH=`pwd`/flutter/bin:$PATH

            brew install --HEAD libimobiledevice
            brew install ideviceinstaller
            brew install ios-deploy

            flutter doctor

Thanks

2 Likes

#2

Hi @ch_kent,

Are you sure that’s where flutter installs its actual binaries? bin/flutter in the repository is just a script (https://github.com/flutter/flutter/blob/master/bin/flutter). Not sure where the actual binary is / what should be cached. That always depends on the tool, what worth to cache and which dir(s) should be cached.

Additionally, if most of the flutter install is downloading some pre-compiled binaries then the cache might not even worth it at all, as the cache have to be downloaded as well, which will most likely take about the same time than just downloading from the official source. E.g. brew by default downloads precompiled tools, meaning brew install usually can’t be made faster as it just downloads the binaries/components.

Typically the best candidates for caching are the files/dirs which you can’t just download from an official source but have to be built locally. There you trade the compile time for cache download, which usually is faster, but this also depends on the tool, how fast or slow the compile of the tool is vs the size of the compiled files.

I’m not saying flutter can’t be cached, just wanted to share a couple of notes / things to consider. Unfortunately we’re not familiar with how flutter install works (what would worth or not worth to cache), you might want to ask that on flutter’s forums/support.

Of course if you’d have any questions just let us know! :slight_smile:

0 Likes

#3

Another option to speed up Flutter installation process is to include Flutter SDK in the Bitrise stacks. Beta and dev versions are available as archives. Linux version is ~300 MB, macOS one about 600 MB.

2 Likes

#4

This is just what I need. I was planning to do the same but just not time.

Is there a repo to show off how to do this ?

The caching idea will really help

0 Likes

#5

How frequently the SDKs are updated? Also, does it matter which version is available, similar to e.g. the Android NDK?

0 Likes

#6

https://flutter.io/sdk-archive/#linux
Dev versions are released every few days. Beta theoretically - every few weeks (https://github.com/flutter/flutter/wiki/Flutter-build-release-channels) but it does not match reality.

No, in beta and dev channels you can download whichever version you want at anytime. Only in master channel there are no version numbers.

0 Likes

#7

So pre-installing Dev versions wouldn’t help much, right? Even for Beta versions I’m not that sure, as we do the updates once a week, so if they release Betas frequently there’s a significant chance that it won’t be the right version for your project, right? I mean it will be either newer or older than the version you develop with but most likely not the exact same version, right?

0 Likes

#8

Yep, it seems that we should wait for release version.

1 Like

#9

Flutter have stable version now, and stable versions will be released every quarter, so it is not every week. Let reconsider faster builds.
Current “Flutter Install” step takes over 2 minutes for every builds, so it is better to add Flutter to stacks.

We generally intend to roll the stable branch every quarter or so, probably with more fanfare than a regular beta roll.
https://github.com/flutter/flutter/wiki/Release-process

1 Like

#10

Hy, thanks for the heads up, I will talk to the developers in charge of this :upside_down_face:

UPDATE: We already have the card to add flutter to the hybrid stack, so it will be available soon :upside_down_face:

3 Likes

#11

Thanks! I’m really looking forward to use the new stack! :upside_down_face:

1 Like

#12

Is there any update on this?

It still takes about 180 seconds to install Flutter on Hybrid stack and no other is available at the moment.

Also, without setting version manually to v1.2.1 it takes more than 5-6 mins to install Flutter stable channel utilizing this workaround.

It means that it’s impossible to build even basic Flutter app on free plan.

If you add Firebase to the iOS app it takes almost 30 minutes to complete initial flutter build and then again 20 minutes to archive .ipa. So in other words it’s impossible to build iOS Flutter app with Firebase on Developer plan.

This is very unpleasant experience as Bitrise is being promoted as mobile focused CI platform.

0 Likes

#13

I’m sad to hear you have these hardships, it is kind of hard to make it faster, because this is how flutter works, and it is out of our reach, we are currently trying to find a solution to cache flutter builds so that part could be faster.

0 Likes