Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement(releasing): change release profile #6202

Merged
merged 6 commits into from
Feb 9, 2021
Merged

enhancement(releasing): change release profile #6202

merged 6 commits into from
Feb 9, 2021

Conversation

fanatid
Copy link
Contributor

@fanatid fanatid commented Jan 22, 2021

Close #5765

opt-level lto codegen_units CFLAGS ("-g0") CFLAGS ("-O3") RUSTFLAGS ("-C link-arg=-s") panic size size (gzip)
3 16 unwind 134_411_208 41_020_507
3 1 unwind 114_708_088 37_408_560
3 ✔️ 1 unwind 73_171_648 25_836_348
3 ✔️ 1 ✔️ unwind 68_340_552 24_670_348
3 ✔️ 1 ✔️ ✔️ unwind 48_812_344 19_773_309
3 ✔️ 1 ✔️ ✔️ ✔️ unwind 48_922_424 19_835_123
3 ✔️ 1 ✔️ ✔️ ✔️ abort 44_924_728 17_758_162
s 16 unwind 183_160_504 48_861_862
s ✔️ 1 unwind 64_934_952 22_350_645
s ✔️ 1 ✔️ unwind 62_383_304 21_589_090
s ✔️ 1 ✔️ ✔️ unwind 40_083_800 16_121_752
s ✔️ 1 ✔️ ✔️ ✔️ unwind 40_636_248 16_347_128
s ✔️ 1 ✔️ ✔️ ✔️ abort 36_257_624 14_357_150
z 16 unwind 182_186_584 48_437_380
z ✔️ 1 ✔️ ✔️ ✔️ abort 34_021_208 13_460_430

I think most relevant release config for us will be:

opt-level = 3
lto = true
panic = "abort"
codegen-units = 1

We can use opt-level = "s" / "z" for smaller size but from guides this looks like affect performance (I tried collect benchmark, but CI fail for lto = true / codegen-units = 1).
Since we distribute vector binary without debug information (because we use RUSTFLAGS="-C link-arg=-s") I think we also can use panic = "abort" (save ~4MB).
I also added an optimization flag (-O3) for C libraries through CFLAGS (discover this when tried to remove debug information from there but then realized that we do not have it for the whole binary).

`unwind` / `abort` backtraces

unwind

thread 'main' panicked at 'Configuration error.', src/cli.rs:206:9
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
---
thread 'main' panicked at 'Configuration error.', src/cli.rs:206:9
stack backtrace:
   0:     0x55fb58ab6960 - <unknown>
   1:     0x55fb58ae1ddc - <unknown>
   2:     0x55fb58aad0e2 - <unknown>
   3:     0x55fb58ab9275 - <unknown>
   4:     0x55fb58ab8f18 - <unknown>
   5:     0x55fb58ab9a11 - <unknown>
   6:     0x55fb56a4fe0e - <unknown>
   7:     0x55fb56a4ff96 - <unknown>
   8:     0x55fb56a4fd5a - <unknown>
   9:     0x55fb52f83a64 - <unknown>
  10:     0x55fb537e4abc - <unknown>
  11:     0x55fb54995759 - <unknown>
  12:     0x55fb52f94bfc - <unknown>
  13:     0x55fb54e4d21b - <unknown>
  14:     0x55fb5350a394 - <unknown>
  15:     0x55fb54a58cd2 - <unknown>
  16:     0x55fb54ce585c - <unknown>
  17:     0x55fb54ce0fbd - <unknown>
  18:     0x55fb53509c92 - <unknown>
  19:     0x55fb54de9b79 - <unknown>
  20:     0x55fb53d1924a - <unknown>
  21:     0x55fb53112d81 - <unknown>
  22:     0x55fb558e8183 - <unknown>
  23:     0x55fb53d1905f - <unknown>
  24:     0x55fb52f91ad2 - <unknown>
  25:     0x55fb52f90d55 - <unknown>
  26:     0x55fb52df8335 - <unknown>
  27:     0x55fb52df8203 - <unknown>
  28:     0x55fb52df81a9 - <unknown>
  29:     0x55fb52df82c9 - <unknown>
  30:     0x55fb58ab9f27 - <unknown>
  31:     0x55fb52df82a8 - <unknown>
  32:     0x55fb52df83bb - <unknown>
  33:     0x7fc1bc9da1e2 - __libc_start_main
  34:     0x55fb52df800e - <unknown>
  35:                0x0 - <unknown>

abort

thread 'main' panicked at 'Configuration error.', src/cli.rs:206:9
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Aborted (core dumped)
---
thread 'main' panicked at 'Configuration error.', src/cli.rs:206:9
stack backtrace:
   0:     0x5557ec6950a0 - <unknown>
   1:     0x5557ec6bfddc - <unknown>
   2:     0x5557ec68b822 - <unknown>
   3:     0x5557ec697915 - <unknown>
   4:     0x5557ec6975b8 - <unknown>
   5:     0x5557ec6980b1 - <unknown>
   6:     0x5557ebe7e65e - <unknown>
   7:     0x5557ebe7e476 - <unknown>
   8:     0x5557ebe7e5c5 - <unknown>
   9:     0x5557e9053c3c - <unknown>
Aborted (core dumped)

@fanatid fanatid self-assigned this Jan 22, 2021
@fanatid fanatid force-pushed the binary-size branch 3 times, most recently from c4654e4 to 236103f Compare January 23, 2021 15:14
Signed-off-by: Kirill Fomichev <fanatid@ya.ru>
Signed-off-by: Kirill Fomichev <fanatid@ya.ru>
@fanatid fanatid added this to the 2021-01-18 Tabula E-Rasa milestone Jan 25, 2021
@fanatid fanatid added the domain: releasing Anything related to releasing Vector label Jan 25, 2021
@fanatid fanatid changed the title [not for merge] benchmark for binary size enhancement(releasing): change release profile Jan 25, 2021
Copy link
Member

@jszwedko jszwedko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @fanatid! I appreciate the table you laid out here.

I'm actually a little surprised that we are stripping debug info via link-arg=-s as it makes crash reports much less useful. I see this was added in 648e82c but I don't see a specific reason given for it.

My thoughts are:

For now we go with opt-level 3, lto, codegen_units=1, panic=unwind, and keep debug symbols in. That still seems to give us a 50% improvement on binary size without losing debug information. The issue this addresses, #6202, seems to just be looking for quick wins and I think that set of flags would give it to us.

We create a separate issue for separating debug symbols from the release binaries as part of the release builds so that we can hold on to them for debugging purposes and to correlate stack traces if users report them. This seems like it will give us another ~50% boon. We can investigate abort vs. unwind then. I've never actually done this, but it seems to be possible to separate the symbols via objcopy followed by a strip to remove the symbols.

The alternative is that we keep going without debug symbols and ask people to run a debug build if they report a crash. I'm open to this as well, but would want to make a conscious choice in light of the trade-offs.

I think people seriously concerned about binary size may also be willing to go the extra mile of a conditional build of vector with exactly the features they use.

Signed-off-by: Kirill Fomichev <fanatid@ya.ru>
Signed-off-by: Kirill Fomichev <fanatid@ya.ru>
@fanatid
Copy link
Contributor Author

fanatid commented Feb 9, 2021

Sounds good, I removed flags for removing debug symbols and changed panic to default unwind. Debug symbols are still removed from C/C++ libraries through CFLAGS (I do not think that we need them).

Checked size again: (shared settings: opt-level: 3, lto: true, codegen_units: 1, CFLAGS: -g0 -O3)

--no-default-features panic size size (gzip)
unwind 68_795_456 24_864_903
abort 63_654_632 63_654_632
✔️ unwind 11_063_112 3_986_200

So if somebody wants super slim size they should consider compiling vector themselves with required features (and required instructions set for performance). Maybe we should add some guide about this.

@fanatid fanatid requested review from a team February 9, 2021 11:05
Copy link
Member

@jszwedko jszwedko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @fanatid !

And agreed, it'd be useful to document how to build with limited features. Do you mind opening an issue for that as well as stripping the debug symbols, but holding on to them as a release artifact?

jszwedko added a commit that referenced this pull request Feb 9, 2021
It's not clear to me why profile.dev was being written to Cargo.toml by
slim-builds.sh given that all of the values are defaulted.

The one value, `incremental`, that is changed, is changed in
`~/.cargo/config` which will override any profiles.

> The incremental value can be overridden globally with the
CARGO_INCREMENTAL environment variable or the build.incremental config
variable.

https://doc.rust-lang.org/cargo/reference/profiles.html#incremental

I think the release profile is similar, but will be removed by
#6202 so I left it for now.

Signed-off-by: Jesse Szwedko <jesse@szwedko.me>
jszwedko added a commit that referenced this pull request Feb 9, 2021
It's not clear to me why profile.dev was being written to Cargo.toml by
slim-builds.sh given that all of the values are defaulted.

The one value, `incremental`, that is changed, is changed in
`~/.cargo/config` which will override any profiles.

> The incremental value can be overridden globally with the
CARGO_INCREMENTAL environment variable or the build.incremental config
variable.

https://doc.rust-lang.org/cargo/reference/profiles.html#incremental

I think the release profile is similar, but will be removed by
#6202 so I left it for now.

Signed-off-by: Jesse Szwedko <jesse@szwedko.me>
Comment on lines -25 to -35
# See defaults https://doc.rust-lang.org/cargo/reference/profiles.html#release
opt-level = 3
debug = false
debug-assertions = false
overflow-checks = false
lto = false
panic = 'unwind'
# Disabled, see build.incremental
# incremental = false
codegen-units = 1
rpath = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the comment it was noted these measures were added because we hit disk size limits on CI. Is that not a problem anymore (or, codegen-units and lto trim enough fat)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure is the disk size limit on CI still an issue or not (@jszwedko ?). I just tested default release profile (lto = false, codegen-units = 16) vs PR profile (lto = true, codegen-units = 1).
default: 2_782_000 kb
PR: 2_869_444 kb

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can see 😄 The release builds still happen on Github Actions runners so they may still hit disk limits.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I think the only real change here is lto = true. We were already building with codgen-units = 1.

@@ -16,6 +16,10 @@ name = "graphql-schema"
path = "src/api/schema/gen.rs"
required-features = ["default-no-api-client"]

[profile.release]
lto = true
codegen-units = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern here is that we had codegen-units = 1 previously and decided to remove it because of how much longer it makes the build take (if I remember correctly).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, lto=true+codegen-units=1 require more time, but we do not need this too often.

Copy link
Member

@jszwedko jszwedko Feb 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were already using codegen-units = 1 previously. The only real change here, I think, is lto.

https://github.com/timberio/vector/pull/6202/files#diff-e5855d7cc5d4b3fdd03bd1cf1291d5bb15017d416fdd822ec7eb735444cd20b5L34

@fanatid fanatid merged commit f5574b5 into master Feb 9, 2021
@fanatid fanatid deleted the binary-size branch February 9, 2021 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: releasing Anything related to releasing Vector
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate how to reduce Vector's binary size
4 participants