speeding-up-build.rst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. Speeding Up a Build
  3. *******************
  4. Build time can be an issue. By default, the build system uses simple
  5. controls to try and maximize build efficiency. In general, the default
  6. settings for all the following variables result in the most efficient
  7. build times when dealing with single socket systems (i.e. a single CPU).
  8. If you have multiple CPUs, you might try increasing the default values
  9. to gain more speed. See the descriptions in the glossary for each
  10. variable for more information:
  11. - :term:`BB_NUMBER_THREADS`:
  12. The maximum number of threads BitBake simultaneously executes.
  13. - :term:`BB_NUMBER_PARSE_THREADS`:
  14. The number of threads BitBake uses during parsing.
  15. - :term:`PARALLEL_MAKE`: Extra
  16. options passed to the ``make`` command during the
  17. :ref:`ref-tasks-compile` task in
  18. order to specify parallel compilation on the local build host.
  19. - :term:`PARALLEL_MAKEINST`:
  20. Extra options passed to the ``make`` command during the
  21. :ref:`ref-tasks-install` task in
  22. order to specify parallel installation on the local build host.
  23. As mentioned, these variables all scale to the number of processor cores
  24. available on the build system. For single socket systems, this
  25. auto-scaling ensures that the build system fundamentally takes advantage
  26. of potential parallel operations during the build based on the build
  27. machine's capabilities.
  28. Additional factors that can affect build speed are:
  29. - File system type: The file system type that the build is being
  30. performed on can also influence performance. Using ``ext4`` is
  31. recommended as compared to ``ext2`` and ``ext3`` due to ``ext4``
  32. improved features such as extents.
  33. - Disabling the updating of access time using ``noatime``: The
  34. ``noatime`` mount option prevents the build system from updating file
  35. and directory access times.
  36. - Setting a longer commit: Using the "commit=" mount option increases
  37. the interval in seconds between disk cache writes. Changing this
  38. interval from the five second default to something longer increases
  39. the risk of data loss but decreases the need to write to the disk,
  40. thus increasing the build performance.
  41. - Choosing the packaging backend: Of the available packaging backends,
  42. IPK is the fastest. Additionally, selecting a singular packaging
  43. backend also helps.
  44. - Using ``tmpfs`` for :term:`TMPDIR`
  45. as a temporary file system: While this can help speed up the build,
  46. the benefits are limited due to the compiler using ``-pipe``. The
  47. build system goes to some lengths to avoid ``sync()`` calls into the
  48. file system on the principle that if there was a significant failure,
  49. the :term:`Build Directory` contents could easily be rebuilt.
  50. - Inheriting the :ref:`ref-classes-rm-work` class:
  51. Inheriting this class has shown to speed up builds due to
  52. significantly lower amounts of data stored in the data cache as well
  53. as on disk. Inheriting this class also makes cleanup of
  54. :term:`TMPDIR` faster, at the
  55. expense of being easily able to dive into the source code. File
  56. system maintainers have recommended that the fastest way to clean up
  57. large numbers of files is to reformat partitions rather than delete
  58. files due to the linear nature of partitions. This, of course,
  59. assumes you structure the disk partitions and file systems in a way
  60. that this is practical.
  61. Aside from the previous list, you should keep some trade offs in mind
  62. that can help you speed up the build:
  63. - Remove items from
  64. :term:`DISTRO_FEATURES`
  65. that you might not need.
  66. - Exclude debug symbols and other debug information: If you do not need
  67. these symbols and other debug information, disabling the ``*-dbg``
  68. package generation can speed up the build. You can disable this
  69. generation by setting the
  70. :term:`INHIBIT_PACKAGE_DEBUG_SPLIT`
  71. variable to "1".
  72. - Disable static library generation for recipes derived from
  73. ``autoconf`` or ``libtool``: Here is an example showing how to
  74. disable static libraries and still provide an override to handle
  75. exceptions::
  76. STATICLIBCONF = "--disable-static"
  77. STATICLIBCONF:sqlite3-native = ""
  78. EXTRA_OECONF += "${STATICLIBCONF}"
  79. .. note::
  80. - Some recipes need static libraries in order to work correctly
  81. (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides,
  82. as in the previous example, account for these kinds of
  83. exceptions.
  84. - Some packages have packaging code that assumes the presence of
  85. the static libraries. If so, you might need to exclude them as
  86. well.