Merge pull request #310 from tonistiigi/faster-load

solver: faster vertex loading
docker-18.09
Akihiro Suda 2018-03-19 14:38:20 +09:00 committed by GitHub
commit e37d938d94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 3 deletions

View File

@ -190,13 +190,21 @@ func (jl *JobList) Close() {
func (jl *JobList) load(v, parent Vertex, j *Job) (Vertex, error) { func (jl *JobList) load(v, parent Vertex, j *Job) (Vertex, error) {
jl.mu.Lock() jl.mu.Lock()
defer jl.mu.Unlock() defer jl.mu.Unlock()
return jl.loadUnlocked(v, parent, j)
cache := map[Vertex]Vertex{}
return jl.loadUnlocked(v, parent, j, cache)
} }
func (jl *JobList) loadUnlocked(v, parent Vertex, j *Job) (Vertex, error) { func (jl *JobList) loadUnlocked(v, parent Vertex, j *Job, cache map[Vertex]Vertex) (Vertex, error) {
if v, ok := cache[v]; ok {
return v, nil
}
origVtx := v
inputs := make([]Edge, len(v.Inputs())) inputs := make([]Edge, len(v.Inputs()))
for i, e := range v.Inputs() { for i, e := range v.Inputs() {
v, err := jl.loadUnlocked(e.Vertex, parent, j) v, err := jl.loadUnlocked(e.Vertex, parent, j, cache)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -207,6 +215,7 @@ func (jl *JobList) loadUnlocked(v, parent Vertex, j *Job) (Vertex, error) {
dgstWithoutCache := digest.FromBytes([]byte(fmt.Sprintf("%s-ignorecache", dgst))) dgstWithoutCache := digest.FromBytes([]byte(fmt.Sprintf("%s-ignorecache", dgst)))
// if same vertex is already loaded without cache just use that
st, ok := jl.actives[dgstWithoutCache] st, ok := jl.actives[dgstWithoutCache]
if !ok { if !ok {
@ -269,6 +278,7 @@ func (jl *JobList) loadUnlocked(v, parent Vertex, j *Job) (Vertex, error) {
} }
jl.connectProgressFromState(st, st) jl.connectProgressFromState(st, st)
cache[origVtx] = v
return v, nil return v, nil
} }