Skip to content

Process,Config: use pointer receivers#5088

Merged
lifubang merged 3 commits into
opencontainers:mainfrom
kolyshkin:pointers
Jan 27, 2026
Merged

Process,Config: use pointer receivers#5088
lifubang merged 3 commits into
opencontainers:mainfrom
kolyshkin:pointers

Conversation

@kolyshkin

Copy link
Copy Markdown
Contributor

Config and Process types are quite big (currently 554 and 368 bytes on a 64 bit Linux),
so using non-pointer receivers in its methods results in copying which
is totally unnecessary.

Change their methods to use pointer receivers.

@rata rata left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

Just curious, is there some metric you care about that is improved with this or it's just a "Looking at the code I realized we are doing this, this is wasteful, let's avoid it"?

About the linter, do as you think it is best, fixing it doesn't seem hard... Although not sure I like the suggestion 😂

Rename a function parameter (containerId -> containerID) to avoid a
linter warning:

> var-naming: method parameter containerId should be containerID (revive)

In many other places, including config.json (.linux.uidMappings and
.gidMappings) it is already called containerID, so let's rename.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
The Config type is quite big (currently 554 bytes on a 64 bit Linux)
and using non-pointer receivers in its methods results in copying which
is totally unnecessary.

Change the methods to use pointer receivers.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
The Process type is quite big (currently 368 bytes on a 64 bit Linux)
and using non-pointer receivers in its methods results in copying which
is totally unnecessary.

Change the methods to use pointer receivers.

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

Copy link
Copy Markdown
Contributor Author

Just curious, is there some metric you care about that is improved with this or it's just a "Looking at the code I realized we are doing this, this is wasteful, let's avoid it"?

I think I merely found one case just by looking at the code (don't remember which one), and then I asked claude code to identify similar cases (of a non-pointer receiver and the struct being copied is large). It found a few of which these two are the largest (its estimates of the size were slightly wrong, I re-checked those manually using unsafe.Sizeof).

About the linter, do as you think it is best, fixing it doesn't seem hard... Although not sure I like the suggestion 😂

Fixed (and overall I like the suggestion since in config.json it's containerID).

@kolyshkin kolyshkin requested review from lifubang and rata January 26, 2026 22:26
@lifubang lifubang merged commit 3d60760 into opencontainers:main Jan 27, 2026
38 checks passed
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.

3 participants