Skip to content

Conversation

@ningmingxiao
Copy link
Contributor

speed up nerdctl ps we don't need call get container spec again.

Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
}
}

func GetCommandFromSpec(spec typeurl.Any, trunc, quote bool) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

This code does not need to be a separate function, as it is called only once

Copy link
Contributor Author

@ningmingxiao ningmingxiao Feb 4, 2026

Choose a reason for hiding this comment

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

since spec have much data, If I use it into a function, it may cause quickly gc (gc may happen after the function return)
if I use it into a for loop (gc may happen after every loop). @AkihiroSuda

Copy link
Member

Choose a reason for hiding this comment

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

You can just create a scope with {}

Also please add the code comments about GC

return nil, err
}
return prepareContainers(ctx, client, containers, cMap, options)
return prepareContainers(ctx, client, &containers, cMap, options)
Copy link
Member

Choose a reason for hiding this comment

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

why?

}
li.Size = containerSize
}
(*containers)[i] = nil
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

@ningmingxiao ningmingxiao Feb 4, 2026

Choose a reason for hiding this comment

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

here I want to let gc recycle the memory quickly

Copy link
Member

Choose a reason for hiding this comment

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

That behavior has to be explained in the code comments in the function declaration

@AkihiroSuda
Copy link
Member

speed up

Any benchmark results?

@ningmingxiao
Copy link
Contributor Author

1000 container speedup 1-2s @AkihiroSuda

@ningmingxiao
Copy link
Contributor Author

ningmingxiao commented Feb 4, 2026

I find nerdctl ps use about 1g memory when container spec size is too big there are many env in spec (because user use enableServiceLinks:true and k8s has many services )
see :containerd/containerd#12846
image

@AkihiroSuda AkihiroSuda added this to the v2.3.0 milestone Feb 4, 2026
@ningmingxiao
Copy link
Contributor Author

we can wait containerd/containerd#12846 or containerd/containerd#12862 to be merged. @AkihiroSuda

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.

2 participants