Skip to content

Commit

Permalink
fix(core): use par_sort
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli committed Jun 20, 2023
1 parent bdd0622 commit 26dbc25
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
21 changes: 5 additions & 16 deletions packages/nx/src/native/hasher.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
#![allow(unused)]

use crate::native::types::FileData;
use crate::native::utils::glob::build_glob_set;
use crate::native::utils::path::Normalize;
use crate::native::walker::nx_walker;
use anyhow::anyhow;
use crossbeam_channel::unbounded;
use globset::{Glob, GlobSetBuilder};
use ignore::WalkBuilder;
use itertools::Itertools;
use std::cmp::Ordering;
use rayon::prelude::*;
use std::collections::HashMap;
use std::path::Path;
use std::thread::available_parallelism;
use xxhash_rust::xxh3;

type FileHashes = HashMap<String, String>;

#[napi]
fn hash_array(input: Vec<String>) -> String {
pub fn hash_array(input: Vec<String>) -> String {
let joined = input.join(",");
let content = joined.as_bytes();
xxh3::xxh3_64(content).to_string()
}

#[napi]
fn hash_file(file: String) -> Option<FileData> {
pub fn hash_file(file: String) -> Option<FileData> {
let Ok(content) = std::fs::read(&file) else {
return None;
};
Expand All @@ -36,7 +25,7 @@ fn hash_file(file: String) -> Option<FileData> {
}

#[napi]
fn hash_files(workspace_root: String) -> HashMap<String, String> {
pub fn hash_files(workspace_root: String) -> HashMap<String, String> {
nx_walker(workspace_root, |rec| {
let mut collection: HashMap<String, String> = HashMap::new();
for (path, content) in rec {
Expand Down Expand Up @@ -74,7 +63,7 @@ fn hash_files_matching_globs(
}

// Sort the file data so that its in deterministically ordered by file path
hashes.sort();
hashes.par_sort();

let sorted_file_hashes: Vec<String> =
hashes.into_iter().map(|file_data| file_data.hash).collect();
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/native/workspace/get_nx_workspace_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn get_workspace_files_native(
trace!(?root_map);

// Files need to be sorted each time because when we do hashArray in the TaskHasher.js, the order of the files should be deterministic
file_data.sort();
file_data.par_sort();

let file_locations = file_data
.into_par_iter()
Expand Down

0 comments on commit 26dbc25

Please sign in to comment.