Skip to content

Commit 976e5b9

Browse files
committed
perf: use Arc<str> for diffs and Arc<PathBuf> for git fetch
Change FileChange::diff from Arc<String> to Arc<str>, saving 8 bytes per FileChange (16 vs 24 byte fat pointer). Share work_dir via Arc<PathBuf> in fetch_file_contents instead of cloning PathBuf per spawned task.
1 parent 16c8232 commit 976e5b9

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/services/git.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl GitService {
122122
files.push(FileChange {
123123
path: file_path,
124124
status,
125-
diff: Arc::new(diff),
125+
diff: Arc::from(diff),
126126
additions,
127127
deletions,
128128
category,
@@ -194,9 +194,10 @@ impl GitService {
194194
paths: &[PathBuf],
195195
) -> (HashMap<PathBuf, String>, HashMap<PathBuf, String>) {
196196
let mut set = tokio::task::JoinSet::new();
197+
let work_dir: Arc<PathBuf> = Arc::new(self.work_dir.clone());
197198

198199
for path in paths {
199-
let work_dir = self.work_dir.clone();
200+
let work_dir = Arc::clone(&work_dir);
200201
let path = path.clone();
201202
set.spawn(async move {
202203
let staged =

tests/analyzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn make_file_change(path: &str, diff: &str, additions: usize, deletions: usize)
1515
FileChange {
1616
path: PathBuf::from(path),
1717
status: ChangeStatus::Added,
18-
diff: Arc::new(diff.to_string()),
18+
diff: Arc::from(diff),
1919
additions,
2020
deletions,
2121
category: FileCategory::from_path(&PathBuf::from(path)),

tests/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn make_file_change(
1919
FileChange {
2020
path: PathBuf::from(path),
2121
status,
22-
diff: Arc::new(diff.to_string()),
22+
diff: Arc::from(diff),
2323
additions,
2424
deletions,
2525
category: FileCategory::from_path(&PathBuf::from(path)),

0 commit comments

Comments
 (0)