libmacchina icon indicating copy to clipboard operation
libmacchina copied to clipboard

Use Rust_Search in count_pkgs

Open Carterpersall opened this issue 2 years ago • 1 comments

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()

Carterpersall avatar Jan 26 '23 18:01 Carterpersall

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 avatar Feb 15 '23 23:02 grtcdr

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.

grtcdr avatar May 10 '24 22:05 grtcdr