-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5fe3f5
commit 44c9073
Showing
11 changed files
with
765 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,10 @@ | ||
[workspace] | ||
members = ["kondo-lib", "path-trie"] | ||
resolver = "2" | ||
|
||
[workspace.dependencies] | ||
path-trie = { path = "./path-trie" } | ||
|
||
[profile.release] | ||
lto = "thin" | ||
codegen-units = 1 |
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,11 @@ | ||
[package] | ||
name = "kondo-lib" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
crossbeam-channel = "0.5.8" | ||
crossbeam-deque = "0.8.3" | ||
crossbeam-utils = "0.8.16" | ||
enum_dispatch = "0.3.12" | ||
path-trie = { workspace = true } |
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,119 @@ | ||
mod project; | ||
mod search; | ||
|
||
use std::{path::PathBuf, thread::available_parallelism, time::Duration}; | ||
|
||
use crossbeam_channel::unbounded; | ||
use crossbeam_deque::{Injector, Worker}; | ||
use crossbeam_utils::{atomic::AtomicCell, sync::Parker}; | ||
pub use project::ProjectEnum; | ||
|
||
use crate::search::search_thread; | ||
|
||
fn run_local() { | ||
let injector = Injector::<PathBuf>::new(); | ||
|
||
let thread_count = available_parallelism() | ||
.unwrap_or(std::num::NonZeroUsize::new(4).unwrap()) | ||
.get(); | ||
|
||
let workers = (0..thread_count) | ||
.map(|_| (Worker::<PathBuf>::new_fifo(), Parker::new())) | ||
.collect::<Vec<_>>(); | ||
|
||
let stealers = workers | ||
.iter() | ||
.map(|w| Worker::stealer(&w.0)) | ||
.collect::<Vec<_>>(); | ||
|
||
let thread_work_references = workers | ||
.iter() | ||
.map(|w| (w.1.unparker().clone(), AtomicCell::new(true))) | ||
.collect::<Vec<_>>(); | ||
|
||
let finished = AtomicCell::new(false); | ||
|
||
let initial_paths = vec![ | ||
PathBuf::from("/Users/choc/junk-code"), // std::env::current_dir().unwrap() | ||
]; | ||
|
||
for path in initial_paths.into_iter() { | ||
injector.push(path); | ||
} | ||
|
||
let worker_thread_idxs = (0..workers.len()).collect::<Vec<_>>(); | ||
|
||
let (result_sender, r) = unbounded(); | ||
|
||
let start = std::time::Instant::now(); | ||
|
||
{ | ||
let senders = (0..thread_count) | ||
.map(|_| result_sender.clone()) | ||
.collect::<Vec<_>>(); | ||
|
||
drop(result_sender); | ||
|
||
std::thread::scope(|s| { | ||
for (i, (w, p)) in workers.into_iter().enumerate() { | ||
let active_ref = &thread_work_references[i].1; | ||
let sender = &senders[i]; | ||
let i = &worker_thread_idxs[i]; | ||
s.spawn(|| { | ||
search_thread(i, w, &injector, &stealers, p, active_ref, &finished, sender) | ||
}); | ||
} | ||
|
||
loop { | ||
std::thread::sleep(Duration::from_millis(10)); | ||
|
||
if thread_work_references | ||
.iter() | ||
.any(|(_, active)| active.load()) | ||
{ | ||
let mut sleeping_threads = 0; | ||
Check warning on line 74 in kondo-lib/src/lib.rs
|
||
for (p, active) in thread_work_references.iter() { | ||
if !active.load() { | ||
sleeping_threads += 1; | ||
p.unpark(); | ||
} | ||
} | ||
// println!("Sleeping threads: {}", sleeping_threads); | ||
// for (i, s) in stealers.iter().enumerate() { | ||
// print!("{}={} ", i, s.len()); | ||
// } | ||
// println!(); | ||
} else { | ||
finished.store(true); | ||
for (p, _) in thread_work_references.iter() { | ||
p.unpark(); | ||
} | ||
break; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
println!("Done Loop"); | ||
|
||
let mut c = 0; | ||
for r in r { | ||
Check warning on line 100 in kondo-lib/src/lib.rs
|
||
c += 1; | ||
// println!("Found project: {} {}", r.1.name(), r.0.display()); | ||
} | ||
|
||
println!("Took {}ms", start.elapsed().as_millis()); | ||
|
||
println!("Found {} projects", c); | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn it_works() { | ||
run_local(); | ||
assert!(false); | ||
} | ||
} |
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,34 @@ | ||
use std::path::Path; | ||
|
||
use enum_dispatch::enum_dispatch; | ||
|
||
mod node; | ||
mod rust; | ||
mod unity; | ||
|
||
use node::NodeProject; | ||
use rust::RustProject; | ||
use unity::UnityProject; | ||
|
||
#[enum_dispatch] | ||
#[derive(Debug, Clone, Copy)] | ||
pub enum ProjectEnum { | ||
RustProject, | ||
NodeProject, | ||
UnityProject, | ||
} | ||
|
||
impl ProjectEnum { | ||
pub const ALL: [Self; 3] = [ | ||
Self::RustProject(RustProject), | ||
Self::NodeProject(NodeProject), | ||
Self::UnityProject(UnityProject), | ||
]; | ||
} | ||
|
||
#[enum_dispatch(ProjectEnum)] | ||
pub trait Project { | ||
fn name(&self) -> &str; | ||
fn is_project(&self, root_dir: &Path) -> bool; | ||
fn is_artifact(&self, path: &Path) -> bool; | ||
} |
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,20 @@ | ||
use std::path::Path; | ||
|
||
use super::Project; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub struct NodeProject; | ||
|
||
impl Project for NodeProject { | ||
fn name(&self) -> &str { | ||
"Node" | ||
} | ||
|
||
fn is_project(&self, root_dir: &Path) -> bool { | ||
root_dir.join("package.json").exists() | ||
} | ||
|
||
fn is_artifact(&self, path: &Path) -> bool { | ||
path.is_dir() && path.file_name().is_some_and(|f| f == "node_modules") | ||
} | ||
} |
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,20 @@ | ||
use std::path::Path; | ||
|
||
use super::Project; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub struct RustProject; | ||
|
||
impl Project for RustProject { | ||
fn name(&self) -> &str { | ||
"Rust" | ||
} | ||
|
||
fn is_project(&self, root_dir: &Path) -> bool { | ||
root_dir.join("Cargo.toml").exists() | ||
} | ||
|
||
fn is_artifact(&self, path: &Path) -> bool { | ||
path.is_dir() && path.file_name().is_some_and(|f| f == "target") | ||
} | ||
} |
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,20 @@ | ||
use std::path::Path; | ||
|
||
use super::Project; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub struct UnityProject; | ||
|
||
impl Project for UnityProject { | ||
fn name(&self) -> &str { | ||
"Unity" | ||
} | ||
|
||
fn is_project(&self, root_dir: &Path) -> bool { | ||
root_dir.join("Assembly-CSharp.csproj").exists() | ||
} | ||
|
||
fn is_artifact(&self, path: &Path) -> bool { | ||
path.is_dir() && path.file_name().is_some_and(|f| f == "Library") | ||
} | ||
} |
Oops, something went wrong.