Skip to content

Commit

Permalink
Merge pull request #3732 from sipsma/fix-recompute-digests
Browse files Browse the repository at this point in the history
llbsolver: Fix performance of recomputeDigests
  • Loading branch information
sipsma authored Mar 22, 2023
2 parents 3b2b824 + ea69a59 commit deba876
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
29 changes: 29 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func TestIntegration(t *testing.T) {
testMountStubsDirectory,
testMountStubsTimestamp,
testSourcePolicy,
testLLBMountPerformance,
)
}

Expand Down Expand Up @@ -8991,3 +8992,31 @@ func testSourcePolicy(t *testing.T, sb integration.Sandbox) {
require.ErrorContains(t, err, sourcepolicy.ErrSourceDenied.Error())
})
}

func testLLBMountPerformance(t *testing.T, sb integration.Sandbox) {
c, err := New(sb.Context(), sb.Address())
require.NoError(t, err)
defer c.Close()

mntInput := llb.Image("busybox:latest")
st := llb.Image("busybox:latest")
var mnts []llb.State
for i := 0; i < 20; i++ {
execSt := st.Run(
llb.Args([]string{"true"}),
)
mnts = append(mnts, mntInput)
for j := range mnts {
mnts[j] = execSt.AddMount(fmt.Sprintf("/tmp/bin%d", j), mnts[j], llb.SourcePath("/bin"))
}
st = execSt.Root()
}

def, err := st.Marshal(sb.Context())
require.NoError(t, err)

timeoutCtx, cancel := context.WithTimeout(sb.Context(), time.Minute)
defer cancel()
_, err = c.Solve(timeoutCtx, def, SolveOpt{}, nil)
require.NoError(t, err)
}
3 changes: 2 additions & 1 deletion solver/llbsolver/vertex.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func recomputeDigests(ctx context.Context, all map[digest.Digest]*pb.Op, visited
}

if !mutated {
visited[dgst] = dgst
return dgst, nil
}

Expand Down Expand Up @@ -274,7 +275,7 @@ func loadLLB(ctx context.Context, def *pb.Definition, polEngine SourcePolicyEval

for {
newDgst, ok := mutatedDigests[lastDgst]
if !ok {
if !ok || newDgst == lastDgst {
break
}
lastDgst = newDgst
Expand Down

0 comments on commit deba876

Please sign in to comment.