Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
readConfig,loadLabels: stop using regex
Using a globally initialized regex incurs some overhead during package initialization, which is noticeable for all other packages importing it. Besides, there's no need to use regex to perform key=value split. Rewrite both functions without using regex, and add benchmarks, which show that the new code is faster: name old time/op new time/op delta ReadConfig-4 4.86µs ± 1% 3.46µs ± 2% -28.82% (p=0.002 n=6+6) LoadLabels-4 12.7µs ± 3% 6.8µs ± 1% -46.24% (p=0.002 n=6+6) name old alloc/op new alloc/op delta ReadConfig-4 5.08kB ± 0% 4.35kB ± 0% -14.33% (p=0.002 n=6+6) LoadLabels-4 6.49kB ± 0% 6.10kB ± 0% -6.07% (p=0.000 n=6+5) name old allocs/op new allocs/op delta ReadConfig-4 20.0 ± 0% 8.0 ± 0% -60.00% (p=0.002 n=6+6) LoadLabels-4 45.0 ± 0% 45.0 ± 0% ~ (all equal) Besides, the init overhead is eliminated: Before: init github.com/opencontainers/selinux/go-selinux @2.4 ms, 0.088 ms clock, 5016 bytes, 72 allocs After: init github.com/opencontainers/selinux/go-selinux @2.9 ms, 0.001 ms clock, 160 bytes, 8 allocs Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
- Loading branch information