Skip to content

Commit f9cef1c

Browse files
committed
perf: reduce kernel memory usage
1 parent c35d74a commit f9cef1c

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/fs_tree_builder.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ where
7272
path: root,
7373

7474
get_info: |path| {
75-
let stats = match symlink_metadata(path) {
75+
let (is_dir, size) = match symlink_metadata(path) {
7676
Err(error) => {
7777
reporter.report(Event::EncounterError(ErrorReport {
7878
operation: SymlinkMetadata,
@@ -84,10 +84,16 @@ where
8484
children: Vec::new(),
8585
};
8686
}
87-
Ok(stats) => stats,
87+
Ok(stats) => {
88+
// `stats` should be dropped ASAP to avoid piling up kernel memory usage
89+
let is_dir = stats.is_dir();
90+
let size = size_getter.get_size(&stats);
91+
reporter.report(Event::ReceiveData(size));
92+
(is_dir, size)
93+
}
8894
};
8995

90-
let children: Vec<_> = if stats.is_dir() {
96+
let children: Vec<_> = if is_dir {
9197
match read_dir(path) {
9298
Err(error) => {
9399
reporter.report(Event::EncounterError(ErrorReport {
@@ -115,9 +121,6 @@ where
115121
Vec::new()
116122
};
117123

118-
let size = size_getter.get_size(&stats);
119-
reporter.report(Event::ReceiveData(size));
120-
121124
Info { size, children }
122125
},
123126

0 commit comments

Comments
 (0)