fontdb icon indicating copy to clipboard operation
fontdb copied to clipboard

Library uses not optimal is_file implementation

Open qarmin opened this issue 1 year ago • 1 comments

When running my app, I found strange is_file in flamegraph(look at the right side of flamegraph)

Screenshot from 2023-12-10 10-55-41

Path.is_file() - get file metadata from disk which is slow and redundant, because DirEntry already read if this is file or not

Entire function load_system_fonts takes 7.46% time of running app and is_file 0.91%, so changing this code will give free 12% performance boost.

The only thing that needs to be changed is to change from - https://github.com/RazrFalcon/fontdb/blob/c3274d016cad92fac744d76a91e4554fe51c5745/src/lib.rs#L315C2-L318

let path = entry.path();
if path.is_file() {
} else if path.is_dir() {
}

into

let file_type = entry.file_type();
if file_type.is_file() {
} else if file_type.is_dir() {
}

qarmin avatar Dec 10 '23 10:12 qarmin

Interesting. Patches are welcome.

RazrFalcon avatar Dec 10 '23 12:12 RazrFalcon

Fixed by https://github.com/RazrFalcon/fontdb/pull/65

RazrFalcon avatar May 10 '24 15:05 RazrFalcon