forked from kopia/kopia
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(repository): added fs.DirectoryIterator (kopia#3365)
* refactor(repository): added fs.DirectoryIterator This significantly reduces number of small allocations while taking snapshots of lots of files, which leads to faster snapshots. ``` $ runbench --kopia-exe ~/go/bin/kopia \ --compare-to-exe ~/go/bin/kopia-baseline --min-duration 30s \ ./snapshot-linux-parallel-4.sh DIFF duration: current:5.1 baseline:5.8 change:-13.0 % DIFF repo_size: current:1081614127.6 baseline:1081615302.8 change:-0.0 % DIFF num_files: current:60.0 baseline:60.0 change:0% DIFF avg_heap_objects: current:4802666.0 baseline:4905741.8 change:-2.1 % DIFF avg_heap_bytes: current:737397275.2 baseline:715263289.6 change:+3.1 % DIFF avg_ram: current:215.0 baseline:211.5 change:+1.6 % DIFF max_ram: current:294.8 baseline:311.4 change:-5.3 % DIFF avg_cpu: current:167.3 baseline:145.3 change:+15.1 % DIFF max_cpu: current:227.2 baseline:251.0 change:-9.5 % ``` * changed `Next()` API * mechanical move of the iterator to its own file * clarified comment * pr feedback * mechanical move of all localfs dependencies on os.FileInfo to a separate file * Update fs/entry.go Co-authored-by: ashmrtn <[email protected]> * Update fs/entry_dir_iterator.go Co-authored-by: Julio Lopez <[email protected]> * doc: clarified valid results from Next() --------- Co-authored-by: ashmrtn <[email protected]> Co-authored-by: Julio Lopez <[email protected]>
- Loading branch information
1 parent
6602772
commit c8d1b22
Showing
27 changed files
with
524 additions
and
514 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package fs | ||
|
||
import "context" | ||
|
||
type staticIterator struct { | ||
cur int | ||
entries []Entry | ||
err error | ||
} | ||
|
||
func (it *staticIterator) Close() { | ||
} | ||
|
||
func (it *staticIterator) Next(ctx context.Context) (Entry, error) { | ||
if it.cur < len(it.entries) { | ||
v := it.entries[it.cur] | ||
it.cur++ | ||
|
||
return v, it.err | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
// StaticIterator returns a DirectoryIterator which returns the provided | ||
// entries in order followed by a given final error. | ||
// It is not safe to concurrently access directory iterator. | ||
func StaticIterator(entries []Entry, err error) DirectoryIterator { | ||
return &staticIterator{0, entries, err} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.