Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readCon speedup #155

Merged
merged 1 commit into from Sep 9, 2021
Merged

readCon speedup #155

merged 1 commit into from Sep 9, 2021

Conversation

kolyshkin
Copy link
Collaborator

When looking at runc strace output, I noticed that selinux attr files
are read byte by byte:

read(8, "u", 1) = 1
read(8, "n", 1) = 1
....

Apparently, this happens because fmt.Fscanf("%s") works that way.

Let's read the whole file via ioutil.ReadAll instead.

The added benchmark shows a drastic improvement:

name            old time/op    new time/op    delta
CurrentLabel-4    26.4µs ± 1%     4.3µs ± 1%   -83.73%  (p=0.004 n=6+5)

name            old alloc/op   new alloc/op   delta
CurrentLabel-4      352B ± 0%      776B ± 0%  +120.45%  (p=0.002 n=6+6)

name            old allocs/op  new allocs/op  delta
CurrentLabel-4      9.00 ± 0%      7.00 ± 0%   -22.22%  (p=0.002 n=6+6)

Note that increased allocation size is caused by the fact that ReadAll
preallocates a 512 bytes buffer, which is very reasonable.

When looking at runc strace output, I noticed that selinux attr files
are read byte by byte:

	read(8, "u", 1) = 1
	read(8, "n", 1) = 1
	....

Apparently, this happens because fmt.Fscanf("%s") works that way.

Let's read the whole file via ioutil.ReadAll instead.

The added benchmark shows a drastic improvement:

name            old time/op    new time/op    delta
CurrentLabel-4    26.4µs ± 1%     4.3µs ± 1%   -83.73%  (p=0.004 n=6+5)

name            old alloc/op   new alloc/op   delta
CurrentLabel-4      352B ± 0%      776B ± 0%  +120.45%  (p=0.002 n=6+6)

name            old allocs/op  new allocs/op  delta
CurrentLabel-4      9.00 ± 0%      7.00 ± 0%   -22.22%  (p=0.002 n=6+6)

Note that increased allocation size is caused by the fact that ReadAll
preallocates a 512 bytes buffer, which is very reasonable.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Copy link
Collaborator

@rhatdan rhatdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rhatdan rhatdan merged commit 4a1acc5 into opencontainers:main Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants