Skip to content

Commit

Permalink
fix(performance): scan hd in parallel (#38)
Browse files Browse the repository at this point in the history
* fix(performance): scan hd in parallel

* fix(performance): scan hd in parallel

* chore(deps): drop unneeded cargo-insta dependency (#35)

Signed-off-by: Igor Raits <[email protected]>

* fix(performance): scan hd in parallel

* style(format): removed unused import

Co-authored-by: Igor Raits <[email protected]>
  • Loading branch information
imsnif and ignatenkobrain authored Jun 21, 2020
1 parent 40f5d08 commit e050626
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 41 deletions.
169 changes: 142 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2018"
tui = "0.9"
termion = "1.5"
failure = "0.1"
walkdir = "2"
jwalk = "0.5"
signal-hook = "0.1.10"
structopt = "0.3"
filesize = "0.2.0"
Expand Down
8 changes: 4 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ::std::fs::{self, Metadata};
use ::std::mem::ManuallyDrop;
use ::std::path::{Path, PathBuf};
use ::std::path::PathBuf;
use ::std::sync::mpsc::{Receiver, SyncSender};
use ::tui::backend::Backend;

Expand Down Expand Up @@ -101,9 +101,9 @@ where
self.loaded = true;
self.render_and_update_board();
}
pub fn add_entry_to_base_folder(&mut self, file_metadata: &Metadata, entry_path: &Path) {
self.file_tree.add_entry(file_metadata, entry_path);
self.ui_effects.last_read_path = Some(PathBuf::from(entry_path));
pub fn add_entry_to_base_folder(&mut self, file_metadata: &Metadata, entry_path: PathBuf) {
self.file_tree.add_entry(file_metadata, &entry_path);
self.ui_effects.last_read_path = Some(entry_path);
}
pub fn reset_ui_mode(&mut self) {
match self.ui_mode {
Expand Down
20 changes: 15 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ mod state;
mod ui;

use ::failure;
use ::jwalk::Parallelism::RayonDefaultPool;
use ::jwalk::WalkDir;
use ::std::env;
use ::std::io;
use ::std::path::PathBuf;
Expand All @@ -23,7 +25,6 @@ use ::termion::event::{Event as TermionEvent, Key};
use ::termion::raw::IntoRawMode;
use ::tui::backend::Backend;
use ::tui::backend::TermionBackend;
use ::walkdir::WalkDir;

use app::{App, UiMode};
use input::{sigwinch, KeyboardEvents};
Expand Down Expand Up @@ -142,12 +143,21 @@ pub fn start<B>(
let instruction_sender = instruction_sender.clone();
let loaded = loaded.clone();
move || {
'scanning: for entry in WalkDir::new(&path).into_iter() {
'scanning: for entry in WalkDir::new(&path)
.parallelism(RayonDefaultPool)
.skip_hidden(false)
.follow_links(false)
.into_iter()
{
let instruction_sent = match entry {
Ok(entry) => match entry.metadata() {
Ok(file_metadata) => instruction_sender.send(
Instruction::AddEntryToBaseFolder((file_metadata, entry)),
),
Ok(file_metadata) => {
let entry_path = entry.path();
instruction_sender.send(Instruction::AddEntryToBaseFolder((
file_metadata,
entry_path,
)))
}
Err(_) => {
instruction_sender.send(Instruction::IncrementFailedToRead)
}
Expand Down
Loading

0 comments on commit e050626

Please sign in to comment.