runc icon indicating copy to clipboard operation
runc copied to clipboard

Do not use regexp

Open kolyshkin opened this issue 3 years ago • 7 comments

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)

kolyshkin avatar Apr 15 '22 18:04 kolyshkin

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.

kolyshkin avatar Apr 15 '22 18:04 kolyshkin

slow

Yes, but not the bottleneck of runc AFAICS. I don’t see necessity to remove regexp.

AkihiroSuda avatar Apr 17 '22 09:04 AkihiroSuda

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).

kolyshkin avatar May 03 '22 01:05 kolyshkin

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.

kolyshkin avatar May 24 '22 18:05 kolyshkin

cilium/ebpf bump moved to https://github.com/opencontainers/runc/pull/3491, will rebase once merged.

kolyshkin avatar May 26 '22 20:05 kolyshkin

urfave/cli bump moved to https://github.com/opencontainers/runc/pull/3484, will rebase once merged.

kolyshkin avatar May 26 '22 20:05 kolyshkin

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.

kolyshkin avatar Jul 14 '22 20:07 kolyshkin

@thaJeztah addressed your comments, PTAL

kolyshkin avatar Nov 02 '22 17:11 kolyshkin

@thaJeztah @mrunalp I have documented the function, PTAL

kolyshkin avatar Dec 16 '22 02:12 kolyshkin