Skip to content

optimize: reduce unnecessary function calls#5048

Open
ningmingxiao wants to merge 1 commit into
containerd:mainfrom
ningmingxiao:speed_up
Open

optimize: reduce unnecessary function calls#5048
ningmingxiao wants to merge 1 commit into
containerd:mainfrom
ningmingxiao:speed_up

Conversation

@ningmingxiao

@ningmingxiao ningmingxiao commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

reduce about 100ms
ref:#5047

@ningmingxiao ningmingxiao force-pushed the speed_up branch 2 times, most recently from 32becea to 4058db1 Compare July 6, 2026 09:54
@ningmingxiao ningmingxiao marked this pull request as draft July 6, 2026 10:02
@ningmingxiao ningmingxiao marked this pull request as ready for review July 6, 2026 10:04
@ningmingxiao ningmingxiao marked this pull request as draft July 6, 2026 10:27
@ningmingxiao ningmingxiao marked this pull request as ready for review July 6, 2026 11:12
@AkihiroSuda AkihiroSuda requested a review from haytok July 7, 2026 02:36
@AkihiroSuda AkihiroSuda added this to the v2.4.0 milestone Jul 7, 2026
Comment thread pkg/containerutil/containerutil.go Outdated
Comment thread cmd/nerdctl/container/container_run.go
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
@ningmingxiao ningmingxiao changed the title optimize: optimize healthcheck optimize: reduce unnecessary function calls Jul 10, 2026
@AkihiroSuda AkihiroSuda requested a review from Copilot July 12, 2026 19:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR targets the startup-time regression reported in #5047 by reducing repeated container label lookups during healthcheck setup and avoiding unnecessary task.Wait() work in detach mode.

Changes:

  • Extend healthcheck timer APIs (CreateTimer/StartTimer) to accept an already-fetched labels map, and update extraction logic to reuse it.
  • Update container start/run/unpause paths to pass cached labels and skip healthcheck setup when no healthcheck label is present.
  • Adjust nerdctl run flow to avoid calling task.Wait() in detach mode (but currently introduces a wait/start ordering risk for non-detach).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/healthcheck/healthcheck_manager_linux.go Reuses caller-provided labels to avoid repeated container.Labels() calls during healthcheck timer setup.
pkg/healthcheck/healthcheck_manager_windows.go Updates stub signatures to match new healthcheck API.
pkg/healthcheck/healthcheck_manager_freebsd.go Updates stub signatures to match new healthcheck API.
pkg/healthcheck/healthcheck_manager_darwin.go Updates stub signatures to match new healthcheck API.
pkg/containerutil/containerutil.go Passes cached labels into healthcheck setup and skips healthcheck work when not configured.
cmd/nerdctl/container/container_run.go Skips task.Wait() for detach runs and passes cached labels into healthcheck setup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +295 to +299
if hcStr, ok := lab[labels.HealthCheck]; ok && hcStr != "" {
// If container has health checks configured, create and start systemd timer/service files.
if err := healthcheck.CreateTimer(ctx, container, cfg, nerdctlCmd, nerdctlArgs, lab); err != nil {
return fmt.Errorf("failed to create healthcheck timer: %w", err)
}
Comment on lines +503 to +506
statusC, err := task.Wait(ctx)
if err != nil {
return err
}

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

4 participants