I moved a Docker container to a Gentoo base and it went from over a gigabyte with Arch and ~600 MB with Debian to 56 MB
>Dockerfile.gentoo-base
FROM gentoo/stage3:musl
RUN sed -i 's/O2/O3 -march=x86-64-v3 -flto=auto/g' /etc/portage/make.conf
RUN printf 'ACCEPT_KEYWORDS="%s"\n' '~amd64 amd64' >> /etc/portage/make.conf
RUN printf 'GENTOO_MIRRORS="%s $GENTOO_MIRRORS"\n' 'https://cdn.example.org/gentoo' >> /etc/portage/make.conf
RUN printf 'USE="${USE} %s"\n' 'minimal verify-sig lto pgo' >> /etc/portage/make.conf
RUN mkdir -pv /etc/portage/patches/sys-apps/groff && wget -P /etc/portage/patches/sys-apps/groff https://git.alpinelinux.org/aports/plain/main/groff/getopt-gcc15.patch
RUN emerge-webrsync && emerge -v1 sys-devel/binutils && binutils-config latest && . /etc/profile && emerge -v1 sys-devel/gcc && gcc-config latest && . /etc/profile && emerge -vuDN --tree --with-bdeps=y --buildpkg y --keep-going @world && emerge -e @system
RUN emerge dev-lang/go
>Dockerfile.gentoo-ytarchive
FROM local/stage3:musl AS build-env
WORKDIR /go/src/ytarchive
COPY *.go ./
RUN printf "%s\n" '*/* -cairo -glib -introspection -drm -fontconfig -python -readline -libass' > /etc/portage/package.use/zzz-autounmask
RUN emerge -v1 --buildpkg y media-video/ffmpeg
RUN printf 'INSTALL_MASK="%s"\n' "/usr/share/doc /usr/share/info /usr/share/gtk-doc /usr/share/man /usr/include /usr/lib/pkgconfig /usr/lib/cmake" >> /etc/portage/make.conf
RUN emerge -v1 --usepkg y --root-deps=rdeps --with-bdeps=n --root=/sysroot sys-libs/musl app-misc/ca-certificates
RUN emerge -v1 --usepkg y --root-deps=rdeps --with-bdeps=n --root=/sysroot media-video/ffmpeg
ENV GOPATH=/go
ENV PATH=$GOPATH/bin:$PATH
ENV GOTOOLCHAIN=local
RUN go mod init
RUN go get -d -v ./...
RUN go vet -v
RUN go test -v
RUN CGO_ENABLED=0 go build -o /sysroot/usr/bin/ytarchive
RUN [ -e /sysroot/lib ] || ln -sv /usr/lib /sysroot/lib
FROM scratch
COPY --from=build-env /sysroot/ /
ENTRYPOINT ["/usr/bin/ytarchive"]