rules_foreign_cc icon indicating copy to clipboard operation
rules_foreign_cc copied to clipboard

Performance hit when building OpenSSL

Open mvukov opened this issue 4 years ago • 1 comments

So, I have the following config (using rules_foreign_cc 0.7.1, Bazel 4.1, Ubuntu 20.04):

  • workspace file:
http_archive(
    name = "openssl",
    build_file = "//:openssl.BUILD.bazel",
    sha256 = "f89199be8b23ca45fc7cb9f1d8d3ee67312318286ad030f5316aca6462db6c96",
    strip_prefix = "openssl-1.1.1m",
    urls = ["https://www.openssl.org/source/openssl-1.1.1m.tar.gz"],
)
  • build file :
filegroup(
  name = "all_srcs",
  srcs = glob(["**"]),
)

configure_make(
    name = "openssl",
    lib_source = ":all_srcs",
    configure_command = "config",
    configure_options = [
        "no-shared",
        "--libdir=lib",
    ],
    args = ["-j4"],
    out_static_libs = [
        "libssl.a",
        "libcrypto.a",
    ],
    targets = [
        "build_libs",
        "install_dev",
    ],
    visibility = ["//visibility:public"],
)

I build the lib with bazel build @openssl//:openssl and naturally this takes a while. However, I noticed that when I start the build the second time (== ~no work), it takes more than a second. I profiled this with bazel build @openssl//:openssl --profile=/tmp/prof for a repeated build. Then I analyzed the results with bazel analyze-profile /tmp/prof and I get:

WARNING: This information is intended for consumption by Bazel developers only, and may change at any time. Script against it at your own risk
INFO: Profile created on ..., build ID: 5cbca931-16f4-41da-a480-e6994c3f2e83, output base: /home/milan/.cache/bazel/_bazel_milan/ee9c36eb173e0f83296ae67ec81f8b34

=== PHASE SUMMARY INFORMATION ===

Total launch phase time         0.009 s    0.76%
Total init phase time           0.095 s    8.08%
Total target pattern evaluation phase time    0.000 s    0.03%
Total interleaved loading-and-analysis phase time    0.003 s    0.29%
Total preparation phase time    0.000 s    0.08%
Total execution phase time      1.073 s   90.71%
Total finish phase time         0.000 s    0.05%
------------------------------------------------
Total run time                  1.183 s  100.00%

Critical path (1.055 s):
       Time Percentage   Description
    1.055 s  100.00%   action 'BazelWorkspaceStatusAction stable-status.txt'

I tried to get rid of the recursive glob by listing all files in all_srcs (> 3k), but that didn't result in a significant reduction of the build time. Any idea why is this happening?

I found an alternative in BoringSSL (with a native Bazel support), but would like to understand what's going on with OpenSSL and using this repo' rules.

mvukov avatar Jan 31 '22 09:01 mvukov

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_foreign_cc!

github-actions[bot] avatar Jul 30 '22 22:07 github-actions[bot]

This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"

github-actions[bot] avatar Aug 29 '22 22:08 github-actions[bot]