doc/news.texi | 8 ++++++++ ood.go | 24 +++++++++++++++++++++++- usage.go | 2 +- diff --git a/doc/news.texi b/doc/news.texi index 5e91fea61bda22a9823b601e2ba12fac27211a0376c25ee5a378be725394c019..5b5453dac605fee68348414674b6460a98a508663aad9e5a0363cdb3c8569b4f 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -2,6 +2,14 @@ @node News @cindex news @unnumbered News +@anchor{Release 1_27_0} +@section Release 1.27.0 +@itemize +@item + Improved out-of-date check and @file{.do} files search performance, + because of caching their results. +@end itemize + @anchor{Release 1_26_0} @section Release 1.26.0 @itemize diff --git a/ood.go b/ood.go index 024757a998469f2734c29a73a0b502e76619e3dbaba8019fa62259134d12d4c0..2b65f0b335f5a110958346d9d3e8b3f38dc2c1292d50f04bafe9eeb02616f006 100644 --- a/ood.go +++ b/ood.go @@ -47,6 +47,7 @@ OODTgts map[string]struct{} FdOODTgts *os.File FdOODTgtsLock *os.File + OODCache map[string]bool = make(map[string]bool) FileExistsCache map[string]bool = make(map[string]bool) ErrMissingTarget = errors.New("invalid format of .rec: missing Target") @@ -128,10 +129,16 @@ func isOOD(cwd, tgtOrig string, level int, seen map[string]struct{}) (bool, error) { indent := strings.Repeat(". ", level) tracef(CDebug, "ood: %s%s checking", indent, tgtOrig) cwd, tgt := cwdAndTgt(path.Join(cwd, tgtOrig)) + ood, cached := OODCache[path.Join(cwd, tgt)] + if cached { + tracef(CDebug, "ood: %s%s -> cached: %v", indent, tgtOrig, ood) + return ood, nil + } depPath := path.Join(cwd, RedoDir, tgt+DepSuffix) fdDep, err := os.Open(depPath) if err != nil { tracef(CDebug, "ood: %s%s -> no dep: %s", indent, tgtOrig, depPath) + OODCache[path.Join(cwd, tgt)] = true return true, nil } depInfo, err := depRead(fdDep) @@ -142,13 +149,14 @@ } if depInfo.build == BuildUUID { tracef(CDebug, "ood: %s%s -> already built", indent, tgtOrig) + OODCache[path.Join(cwd, tgt)] = false return false, nil } if !FileExists(path.Join(cwd, tgt)) { tracef(CDebug, "ood: %s%s -> non-existent", indent, tgtOrig) + OODCache[path.Join(cwd, tgt)] = true return true, nil } - ood := false for _, dep := range depInfo.ifcreates { if FileExists(path.Join(cwd, dep)) { @@ -169,12 +177,21 @@ return ood, TgtError{tgtOrig, fmt.Errorf("invalid format of .rec: %w", err)} } theirHsh := m["Hash"] tracef(CDebug, "ood: %s%s -> %s: checking", indent, tgtOrig, dep) + ood, cached = OODCache[path.Join(cwd, dep)] + if cached { + tracef(CDebug, "ood: %s%s -> %s: cached: %v", indent, tgtOrig, dep, ood) + if ood { + goto Done + } + continue + } inode, err := inodeFromFileByPath(path.Join(cwd, dep)) if err != nil { if os.IsNotExist(err) { tracef(CDebug, "ood: %s%s -> %s: not exists", indent, tgtOrig, dep) ood = true + OODCache[path.Join(cwd, dep)] = ood goto Done } return ood, TgtError{tgtOrig, err} @@ -183,6 +200,7 @@ if inode.Size != theirInode.Size { tracef(CDebug, "ood: %s%s -> %s: size differs", indent, tgtOrig, dep) ood = true + OODCache[path.Join(cwd, dep)] = ood goto Done } if InodeTrust != InodeTrustNone && inode.Equals(theirInode) { @@ -201,6 +219,7 @@ } if theirHsh != hsh { tracef(CDebug, "ood: %s%s -> %s: hash differs", indent, tgtOrig, dep) ood = true + OODCache[path.Join(cwd, dep)] = ood goto Done } tracef(CDebug, "ood: %s%s -> %s: same hash", indent, tgtOrig, dep) @@ -212,11 +231,13 @@ continue } if isSrc(cwd, dep) { tracef(CDebug, "ood: %s%s -> %s: is source", indent, tgtOrig, dep) + OODCache[path.Join(cwd, dep)] = false continue } if _, ok := seen[cwdMustRel(cwd, dep)]; ok { tracef(CDebug, "ood: %s%s -> %s: was always built", indent, tgtOrig, dep) + OODCache[path.Join(cwd, dep)] = false continue } @@ -234,6 +255,7 @@ } Done: tracef(CDebug, "ood: %s%s: %v", indent, tgtOrig, ood) + OODCache[path.Join(cwd, tgt)] = ood return ood, nil } diff --git a/usage.go b/usage.go index 7ba89b46961f16087914c9875cf530a07b629ac4aa8eebe25025d4050e54c9b5..9abaa9c4d2490cc4f8e9ec22f1fe6002d624b391600fad082a7976fb9e7baa0b 100644 --- a/usage.go +++ b/usage.go @@ -24,7 +24,7 @@ "os" ) const ( - Version = "1.26.0" + Version = "1.27.0" Warranty = `Copyright (C) 2020-2022 Sergey Matveev This program is free software: you can redistribute it and/or modify