Macchina-CLI / libmacchina

A library providing access to all sorts of system information.
https://crates.io/crates/libmacchina
MIT License
66 stars 20 forks source link

Use Rust_Search in count_pkgs #131

Closed Carterpersall closed 5 months ago

Carterpersall commented 1 year ago

I've been learning Rust over the last little while by making a fetch program. While working on getting rid of major slowdowns in the code, I found that on Linux count_pkgs() is really slow (over 200 milliseconds). I eventually tracked the slowdown to count_dpkg() and more specifically to get_entries(). It seems that the method currently used to get the entries in a directory is very slow.

So I did some digging online and found the crate Rust_Search (https://github.com/ParthJadhav/Rust_Search). After throwing together an implementation with it, the speed of my fetch program with only package counting enabled went from 232ms to 14.1 ms (16.45x faster).

Here is the code I made that replicates the functionality of count_dpkg():

let dpkg_dir = Path::new("/var/lib/dpkg/info");

SearchBuilder::default()
    .location(dpkg_dir)
    .search_input(".\\.list")
    .build()
    .count()
grtcdr commented 1 year ago

It's nice to see people building tools with libmacchina :)

I'd be more inclined to fix (or consider a pull request addressing) the performance issues causing the slowdowns than depend on yet another package which we may or may not need to solve this pretty straightforward problem.

grtcdr commented 5 months ago

I'm going to close this issue for now, please consider my feedback regarding the unnecessary addition of a dependency if you decide to open a pull request.