Skip to content

Packages (Linux): Improve emerge detection speed#2406

Open
keremgokcek wants to merge 2 commits into
fastfetch-cli:devfrom
keremgokcek:dev
Open

Packages (Linux): Improve emerge detection speed#2406
keremgokcek wants to merge 2 commits into
fastfetch-cli:devfrom
keremgokcek:dev

Conversation

@keremgokcek

@keremgokcek keremgokcek commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes emerge package count detection faster.

Changes

Instead of listing every package's directory in every category to check if SIZE file exist, now it just counts the number of directories in every category folder. This decreases the number of directory listing operations by the number of packages. It's especially noticeable on cold boots.

Documentation of directory: https://wiki.gentoo.org/wiki//var/db/pkg

i7-5500U + SSD with 889 emerge and 11 flatpak user packages installed:
On cold boot: 350 ms -> 30 ms
On regular usage: 3 ms -> 0.9 ms

C2D T7200 + HDD with 438 emerge packages installed:
On cold boot: 2480 ms -> 1000 ms
On regular usage: 1.9 ms -> 0.8 ms

Checklist

  • I have tested my changes locally.

Copilot AI review requested due to automatic review settings June 20, 2026 12:56
@codacy-production

codacy-production Bot commented Jun 20, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves Gentoo (emerge/Portage) package counting performance on Linux by avoiding recursive per-package file existence checks under /var/db/pkg and instead aggregating directory counts per category.

Changes:

  • Added getEmergePackagesImpl() / getEmergePackages() to count installed emerge packages by summing directory counts within each Portage category.
  • Switched EMERGE counting in getPackageCounts() from countFilesRecursive(..., "SIZE") to the new directory-count approach.

Comment on lines +469 to +473
struct dirent *entry;
while ((entry = readdir(dirp)) != NULL)
{
if (entry->d_type != DT_DIR || entry->d_name[0] == '.')
continue;
Comment thread src/detection/packages/packages_linux.c Outdated
Comment on lines +461 to +462
static uint32_t getEmergePackagesImpl(FFstrbuf* baseDir)
{
Comment thread src/detection/packages/packages_linux.c Outdated
Comment on lines +480 to +481
static uint32_t getEmergePackages(FFstrbuf* baseDir, const char* dirname)
{
@CarterLi

Copy link
Copy Markdown
Member

The old code was introduced in #131, 4 years ago

@ceamac Can you recall why did you choose to check if SIZE exists?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants