Increase of 7MB in the size of the Lix derivation on Linux #308

Open
opened 2024-05-12 13:53:14 +00:00 by raito · 19 comments
Owner

From https://github.com/NixOS/nixpkgs/pull/310194 we have the following size reports:

Darwin:
`aarch64-darwin`: `/nix/store/rb4s95dpl9s33zax58jp15dgg06a0m6h-lix-2.90-beta.1                        	 14.6M` (+1MB with Nix!)
`x86_64-darwin`: `/nix/store/awcgvimn965qz3qyiqrxpd0cfi381fhl-lix-2.90-beta.1                        	 14.9M` (+0.7MB with Nix!)

Linux:
`x86_64-linux`: `/nix/store/23paa6b9ijxq6lwxl5ad0bmly01rrj52-lix-2.90-beta.1                                	 18.7M` (+7MB with Nix)
`aarch64-linux`: `/nix/store/w4i6zfqh3i7kavn2hr4gyk645hbvfxz3-lix-2.90-beta.1                                 	 18.4M` (+8MB with Nix)

The Linux derivation size are fishy.

From https://github.com/NixOS/nixpkgs/pull/310194 we have the following size reports: ``` Darwin: `aarch64-darwin`: `/nix/store/rb4s95dpl9s33zax58jp15dgg06a0m6h-lix-2.90-beta.1 14.6M` (+1MB with Nix!) `x86_64-darwin`: `/nix/store/awcgvimn965qz3qyiqrxpd0cfi381fhl-lix-2.90-beta.1 14.9M` (+0.7MB with Nix!) Linux: `x86_64-linux`: `/nix/store/23paa6b9ijxq6lwxl5ad0bmly01rrj52-lix-2.90-beta.1 18.7M` (+7MB with Nix) `aarch64-linux`: `/nix/store/w4i6zfqh3i7kavn2hr4gyk645hbvfxz3-lix-2.90-beta.1 18.4M` (+8MB with Nix) ``` The Linux derivation size are fishy.
raito added the
Area/build-packaging
label 2024-05-12 13:53:26 +00:00
Member

I built the derivation with ninjaFlags = [ "-v" ]; and:

[10/456] g++ -Isrc/libutil/libnixutil.so.p -Isrc/libutil -I../src/libutil -I/nix/store/rh6sv1rpxavhhzprbaqpkqdm4sq39d19-boehm-gc-8.2.6-dev/include -I/nix/store/73ik8xsdqv0grj8z4rplfqhzb5ajd4s3-boost-1.81.0-dev/include -I/nix/store/lpsa98iwl9q7fb2hdiqhqcryyg2kvgnm-libcpuid-0.6.5/include/libcpuid -I/nix/store/j7c8ah9qzr65gkdid7p8r6qj309ngnr0-libseccomp-2.5.5-dev/include -I/nix/store/152md2dw0gf33ag9rqhf5zmh93pvkazx-libarchive-3.7.3-dev/include -I/nix/store/jhkpr5iyyx35c1sg52vdgjpvky03xi1n-brotli-1.1.0-dev/include -I/nix/store/5m7d3z1xcwy0gagkginzqvhcrxifzwqf-openssl-3.0.13-dev/include -I/nix/store/jwhvd9dhwhd0xpx00k7slv4b26n024r6-nlohmann_json-3.11.3/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c++2a -include config.h -Wno-deprecated-declarations -Wimplicit-fallthrough -Werror=switch -Werror=switch-enum -D_GLIBCXX_ASSERTIONS=1 -fsanitize=signed-integer-overflow -fsanitize-undefined-trap-on-error -ffile-prefix-map=../src=src -fPIC -DBOOST_CONTEXT_DYN_LINK=1 -DBOOST_COROUTINES_DYN_LINK=1 -DBOOST_CONTAINER_DYN_LINK=1 -DBOOST_ALL_NO_LIB -MD -MQ src/libutil/libnixutil.so.p/position.cc.o -MF src/libutil/libnixutil.so.p/position.cc.o.d -o src/libutil/libnixutil.so.p/position.cc.o -c ../src/libutil/position.cc

... no optimization flags?! That would probably explain it.

I built the derivation with `ninjaFlags = [ "-v" ];` and: ``` [10/456] g++ -Isrc/libutil/libnixutil.so.p -Isrc/libutil -I../src/libutil -I/nix/store/rh6sv1rpxavhhzprbaqpkqdm4sq39d19-boehm-gc-8.2.6-dev/include -I/nix/store/73ik8xsdqv0grj8z4rplfqhzb5ajd4s3-boost-1.81.0-dev/include -I/nix/store/lpsa98iwl9q7fb2hdiqhqcryyg2kvgnm-libcpuid-0.6.5/include/libcpuid -I/nix/store/j7c8ah9qzr65gkdid7p8r6qj309ngnr0-libseccomp-2.5.5-dev/include -I/nix/store/152md2dw0gf33ag9rqhf5zmh93pvkazx-libarchive-3.7.3-dev/include -I/nix/store/jhkpr5iyyx35c1sg52vdgjpvky03xi1n-brotli-1.1.0-dev/include -I/nix/store/5m7d3z1xcwy0gagkginzqvhcrxifzwqf-openssl-3.0.13-dev/include -I/nix/store/jwhvd9dhwhd0xpx00k7slv4b26n024r6-nlohmann_json-3.11.3/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c++2a -include config.h -Wno-deprecated-declarations -Wimplicit-fallthrough -Werror=switch -Werror=switch-enum -D_GLIBCXX_ASSERTIONS=1 -fsanitize=signed-integer-overflow -fsanitize-undefined-trap-on-error -ffile-prefix-map=../src=src -fPIC -DBOOST_CONTEXT_DYN_LINK=1 -DBOOST_COROUTINES_DYN_LINK=1 -DBOOST_CONTAINER_DYN_LINK=1 -DBOOST_ALL_NO_LIB -MD -MQ src/libutil/libnixutil.so.p/position.cc.o -MF src/libutil/libnixutil.so.p/position.cc.o.d -o src/libutil/libnixutil.so.p/position.cc.o -c ../src/libutil/position.cc ``` ... no optimization flags?! That would probably explain it.
Owner

…right, mesonConfigurePhase sets mesonBuildType/-Dbuild_type=plain by default…

…right, mesonConfigurePhase sets `mesonBuildType`/`-Dbuild_type=plain` by default…
Member

With mesonBuildType = "release"; patched in to the nixpkgs expression (and checked that -O3 appears in the build flags):

/nix/store/3nijav5qh5960976z10bmwn99vc8ibik-lix-2.90-beta.1       91.8M
/nix/store/awshr3d8a94v2igyf16jh5p8bw9wf93s-nix-2.18.2    84.4M

So that alone doesn't fix it. Should probably still be fixed (and also in Lix's package.nix maybe?).

With `mesonBuildType = "release";` patched in to the nixpkgs expression (and checked that -O3 appears in the build flags): ``` /nix/store/3nijav5qh5960976z10bmwn99vc8ibik-lix-2.90-beta.1 91.8M /nix/store/awshr3d8a94v2igyf16jh5p8bw9wf93s-nix-2.18.2 84.4M ``` So that alone doesn't fix it. Should probably still be fixed (and also in Lix's `package.nix` maybe?).
Member

Current hypothesis: this is because Nix >= 2.10 on GNU stdenvs uses -flto which Lix doesn't seem to use. This would explain why the discrepancy is only happening on the Linux builds and not the Darwin builds.

Current hypothesis: this is because Nix >= 2.10 on GNU stdenvs uses `-flto` which Lix doesn't seem to use. This would explain why the discrepancy is only happening on the Linux builds and not the Darwin builds.
Member

with -Db_lto=true and mesonBuildType = "release";:

/nix/store/9lhnrg0rwjkk9si9fnpvyrbkkajw32ca-lix-2.90-beta.1       87.4M
/nix/store/awshr3d8a94v2igyf16jh5p8bw9wf93s-nix-2.18.2            84.4M

Getting there.

with `-Db_lto=true` and `mesonBuildType = "release";`: ``` /nix/store/9lhnrg0rwjkk9si9fnpvyrbkkajw32ca-lix-2.90-beta.1 87.4M /nix/store/awshr3d8a94v2igyf16jh5p8bw9wf93s-nix-2.18.2 84.4M ``` Getting there.
Owner

Current hypothesis: this is because Nix >= 2.10 on GNU stdenvs uses -flto which Lix doesn't seem to use. This would explain why the discrepancy is only happening on the Linux builds and not the Darwin builds.

since you say this: lix should really enable lto in nixpkgs. lto makes quite a difference in eval performance (which is why we added it to nix in the first place 🫠)

> Current hypothesis: this is because Nix >= 2.10 on GNU stdenvs uses `-flto` which Lix doesn't seem to use. This would explain why the discrepancy is only happening on the Linux builds and not the Darwin builds. since you say this: lix should *really* enable lto in nixpkgs. lto makes quite a difference in eval performance (which is why we added it to nix in the first place 🫠)
Member

Getting there.

The last 3MB are in very large part attributable to the Rust lix-doc being statically linked into libnixcmd. It's dragging in a good chunk of runtime, from what I can tell. Not exactly sure what can be done there since it's outside of my expertise - maybe it's dead code that could be eliminated with -Wl,--gc-sections and the equivalent of -ffunction-sections on the Rust side of things?

Could also treat as WAI since at least we have an explanation now.

> Getting there. The last 3MB are in very large part attributable to the Rust lix-doc being statically linked into libnixcmd. It's dragging in a good chunk of runtime, from what I can tell. Not exactly sure what can be done there since it's outside of my expertise - maybe it's dead code that could be eliminated with `-Wl,--gc-sections` and the equivalent of `-ffunction-sections` on the Rust side of things? Could also treat as WAI since at least we have an explanation now.
Author
Owner

@delroth Perfect, that makes total sense to me.

@delroth Perfect, that makes total sense to me.
Member

since you say this: lix should really enable lto in nixpkgs. lto makes quite a difference in eval performance (which is why we added it to nix in the first place 🫠)

Should package.nix and/or lix-project/nixos-module also enable it? AFAICT they currently don't, but I might be mistaken.

> since you say this: lix should *really* enable lto in nixpkgs. lto makes quite a difference in eval performance (which is why we added it to nix in the first place 🫠) Should `package.nix` and/or `lix-project/nixos-module` also enable it? AFAICT they currently don't, but I might be mistaken.
Owner

package.nix probably shouldn't (but should give the option), the module may want to override this choice to give a close-to-nixos build result

`package.nix` probably shouldn't (but should give the option), the module may want to override this choice to give a close-to-nixos build result
Owner

now hold your horses though, because release is -O3 and I don't think we want that configuration to even be allowed after we found that gcc warning bug on O3. i think you want debugoptimized which is O2 and has debug info available.

now hold your horses though, because release is -O3 and I don't think we want that configuration to even be *allowed* after we found that gcc warning bug on O3. i think you want debugoptimized which is O2 and has debug info available.
Author
Owner

now hold your horses though, because release is -O3 and I don't think we want that configuration to even be allowed after we found that gcc warning bug on O3. i think you want debugoptimized which is O2 and has debug info available.

For the nixpkgs release?

> now hold your horses though, because release is -O3 and I don't think we want that configuration to even be *allowed* after we found that gcc warning bug on O3. i think you want debugoptimized which is O2 and has debug info available. For the nixpkgs release?
Owner

In general. I am not convinced that O3 is sound in gcc given that warning implies it thinks something can be uninit when it can't be.

In general. I am not convinced that O3 is sound in gcc given that warning implies it thinks something can be uninit when it can't be.
Member

@jade do you have a ref to that warning you're talking about? I didn't see it on my side when building in release mode.

In general I'd say that building with build_type = release is a fairly intuitive thing to do, and users will try and do it. So if we think the set of flags used in that mode is wrong, they should probably be fixed in the Meson config. WDYT?

@jade do you have a ref to that warning you're talking about? I didn't see it on my side when building in `release` mode. In general I'd say that building with `build_type = release` is a fairly intuitive thing to do, and users will try and do it. So if we think the set of flags used in that mode is wrong, they should probably be fixed in the Meson config. WDYT?
Owner

yes that would be #46

yes that would be https://git.lix.systems/lix-project/lix/issues/46
Owner

they should probably be fixed in the Meson config. WDYT?

note that meson doesn't allow you to force a build type or optimization level within meson.build; you can only default it if not specified (and the meson hook in Nixpkgs never uses the default). You can add the -O2 flags yourself, but Meson will probably emit a warning about it and/or apply the flags from its configured build type/opt level

> they should probably be fixed in the Meson config. WDYT? note that meson doesn't allow you to force a build type or optimization level within `meson.build`; you can only *default* it if not specified (and the meson hook in Nixpkgs never uses the default). You can add the `-O2` flags yourself, but Meson will probably emit a warning about it and/or apply the flags from its configured build type/opt level
Owner

can we detect people setting optimization to 3 and throw an error? that's my preference i think.

can we detect people setting optimization to 3 and throw an error? that's my preference i think.
Member

Doesn't that seem premature when there is no evidence of harm from -O3? AFAICT all that has been reported so far is spurious warnings - all Lix tests are still passing.

Doesn't that seem premature when there is no evidence of harm from -O3? AFAICT all that has been reported so far is spurious warnings - all Lix tests are still passing.
Owner

Doesn't that seem premature when there is no evidence of harm from -O3? AFAICT all that has been reported so far is spurious warnings - all Lix tests are still passing.

The thing about the warning being reported is it implies there's an unsound optimization pass, or that that particular warning warns on legit code. And I'm mildly scared of it being the former case.

> Doesn't that seem premature when there is no evidence of harm from -O3? AFAICT all that has been reported so far is spurious warnings - all Lix tests are still passing. The thing about the warning being reported is it implies there's an unsound optimization pass, *or* that that particular warning warns on legit code. And I'm mildly scared of it being the former case.
Sign in to join this conversation.
No milestone
No project
No assignees
5 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#308
No description provided.