Skip to content

perf(ci): build the Service image once for its test shards #4642

Closed

Description

@dan-petty

Problem or Motivation

Each of the 6 Service Image Tests shards builds the service stage again (no-cache-filters: service, .github/workflows/ci.yml:590). This takes 79-89 s per shard plus 13-30 s of buildx setup, about 503 runner-s per run (measured). The Service Image job builds the same target.

Each shard also compiles bytecode for a .venv that lists only the shard files, and it restores a tooling cache that never hits. The shards print no per-test times. The comment at ci.yml:534-535 says that the shards stay under 300 s, but they average 368-507 s (measured).

Saving: 40-50 s per shard, 4-5 runner-min and 6 builds per run (estimated).

Found by the CI and test audit of 2026-11-11. The account runs at most 20 hosted jobs at one time (measured), so each job that does no work makes the queue of each pull request longer.

Proposed Solution & Architectural Design

  • The Service Image job builds once and runs its smoke test and scan. Then it saves the image with docker save and actions/upload-artifact.
  • Each shard gets the image with actions/download-artifact and docker load.
  • Add --durations=10 and -rs to the pytest arguments (ci.yml:653).
  • Skip the tooling cache in the shards.
  • Correct the comment at ci.yml:534-535 (AGENTS.md rule 8).
  • Change _service_image_test_job_problems (tests/invariants/test_architectural_invariants.py:1659) so that it accepts a loaded image of the service stage.
  • Owner decision O1 (2026-11-11) moves Service Image Tests off the PR path, in the item 'perf(ci): run the in-image suite nightly and on image PRs'. After it, this saving applies to the nightly runs and the image-input runs. The two items change the same job, so merge one of them first.

Risk: Low. The artifact adds an upload and a download.

Target Subsystem

SDLC, Git & PR Governance (.github/workflows/ci.yml, tests/invariants/test_architectural_invariants.py).

Existing Tool Considered

docker save and docker load with the official actions/upload-artifact and actions/download-artifact. docker/build-push-action can also write the tar with outputs: type=docker,dest=<file>. No new tool. Cost: about 40,000 tokens and 3 hours.

Acceptance Criteria

  • One build of the service stage per run (from 7).
  • No shard has a build step.
  • The shard mean falls by 40 s or more (from 437 s).
  • Each shard log lists its 10 slowest tests and the reason for each skip.

Dependencies

None.

Activity

  1. added
    source/agent
    type/infra
    scope/ci
    status/new
    value/medium
    effort/medium
    on Nov 11, 2026
  2. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/infra. The perf prefix of the title gives the type.
    • Scope: scope/ci. The (ci) scope of the title gives the scope.
    • Priority: P2-Medium. Measured savings of 4-5 runner-minutes per run and 6 fewer builds reduce queue time, but no functional or security impact justifies P1.
    • Value: Medium. Saves runner capacity and shortens PR queue time for every contributor, but does not change delivered functionality.
    • Effort: Medium. Requires editing ci.yml for artifact upload/download, adding pytest flags, skipping a cache, and updating one invariant test; well-scoped but touches multiple steps.
    • Related: ci(image): move the image checks to one path-filtered workflow #1858, which asks for a different change. Both items change the service image build steps in ci.yml, but #1858 deduplicates the build between ci.yml and release.yml via a reusable workflow, while this candidate shares one build across 6 test shards within ci.yml.
  3. added
    priority/p2-medium
    on Nov 11, 2026
  4. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Observation (run 43093341637, PR #4801, 2026-11-11): in shard 6 of 6 of Service Image Tests, the step Post Build and Load Service Image took 631 s (20:18:15 to 20:28:46 UTC). In shards 1 to 5 the same step took 2 to 7 s. The test step of shard 6 ended at 20:18:15, so the job used about 10 more runner-min, and the Tests & Coverage aggregate waited for it.

    The post step of docker/build-push-action v6 exports the build record and writes the build summary. No workflow sets DOCKER_BUILD_RECORD_UPLOAD or DOCKER_BUILD_SUMMARY (git grep DOCKER_BUILD_ .github/ finds nothing). This is one occurrence; the cause of the slow export is not verified. When this item changes the shard build, consider whether the shards need the build record.

  5. added
    owner/agent
    status/in-review
    and removed
    status/new
    on Nov 12, 2026
  6. removed
    status/in-review
    owner/agent
    on Nov 12, 2026
  7. devops-cli-service commented on Nov 12, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-12 15:46 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/cisource/agenttype/infravalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions