runc
runc copied to clipboard
Do not use regexp
Don't get me wrong, I love regular expressions. But the regexp package is somewhat big and slow, and we can do just fine without.
Remove two last uses of regexp in runc code (modulo tests).
This saves about 200K (2.3%) from the resulting binary, without losing any of the functionality.
~~Currently a draft pending~~
- [x] #3514
- [x] #3484 (which has https://github.com/urfave/cli/pull/1383)
- [x] #3491 (which has https://github.com/cilium/ebpf/pull/642)
- [x] #3543 (which has https://go-review.googlesource.com/c/protobuf/+/402774)
- [x] #3585 (which has https://github.com/docker/go-units/pull/40)
Fedora CI failed with
[04] run rootless tests ... (idmap+cgroup)
tests/rootless.sh: line 44: /etc/subuid.tmp: Read-only file system
make: *** [Makefile:103: localrootlessintegration] Error 1
make: Leaving directory '/vagrant'
which is pretty weird. Perhaps it's the problem with the underlying fs and so the kernel remounted it read-only.
Restarted.
slow
Yes, but not the bottleneck of runc AFAICS. I don’t see necessity to remove regexp.
A few of runc dependencies use regexp as well.
- github.com/docker/go-units: fixed by https://github.com/docker/go-units/pull/40
- github.com/cilium/ebpf: fixed by https://github.com/cilium/ebpf/pull/642
- github.com/urfave/cli (via github.com/russross/blackfriday): being fixed by https://github.com/urfave/cli/pull/1383 (a backport of https://github.com/urfave/cli/pull/1375)
- google.golang.org/protobuf: fixed by https://go-review.googlesource.com/c/protobuf/+/402774
Once (and if) all of these are merged, I am going to bring this out of draft, as it will save us 200K (130K stripped) from the runc binary size (which is about 5%, comparing the stripped binaries).
Currently saves 531K from the stripped binary (which is 5.6% of binary size). Still very far from crun footprint, yet it seems like a worthwhile saving.
cilium/ebpf bump moved to https://github.com/opencontainers/runc/pull/3491, will rebase once merged.
urfave/cli bump moved to https://github.com/opencontainers/runc/pull/3484, will rebase once merged.
Rebased, made a fresh comparison:
[kir@kir-rhat runc]$ go version
go version go1.18.1 linux/amd64
[kir@kir-rhat runc]$ git describe HEAD
v1.1.0-239-g93ad6a85
[kir@kir-rhat runc]$ ls -l runc.main runc.no-regexp
-rwxrwxr-x. 1 kir kir 12999304 Jul 14 13:31 runc.main
-rwxrwxr-x. 1 kir kir 12708080 Jul 14 13:31 runc.no-regexp
[kir@kir-rhat runc]$ strip runc.main runc.no-regexp
[kir@kir-rhat runc]$ ls -l runc.main runc.no-regexp
-rwxrwxr-x. 1 kir kir 9310880 Jul 14 13:33 runc.main
-rwxrwxr-x. 1 kir kir 9100352 Jul 14 13:33 runc.no-regexp
[kir@kir-rhat runc]$ size runc.main runc.no-regexp
text data bss dec hex filename
5645422 3657744 229832 9532998 917646 runc.main
5503086 3587520 229416 9320022 8e3656 runc.no-regexp
So, the saving is about 200K for a stripped binary, which is 2.3% of its size.
@thaJeztah addressed your comments, PTAL
@thaJeztah @mrunalp I have documented the function, PTAL