Skip to content

Conversation

@apocelipes
Copy link
Contributor

File names have known max length limits, so we can use a fixed length stack buf rather than heap allocations.

This reduces 2 heap allocations on the path "/home/apocelipes/.config/fastfetch" and makes createSubfolders run 8% faster:

benchmark

After this optimization, the paramater fileName's length must be less than the PATH_MAX/MAX_PATH, and open/CreateFileA has already checked this for us, so it's not worth to check it again in the createSubfolders.

@apocelipes apocelipes marked this pull request as draft November 9, 2024 14:14
@apocelipes apocelipes marked this pull request as ready for review November 9, 2024 14:16
@apocelipes
Copy link
Contributor Author

It's not worth using strncat, it is noticeably slower than pathTail in benchmarks. Let the code be a bit longer can get better performance.

@CarterLi
Copy link
Member

CarterLi commented Nov 9, 2024

I don't like the change. Maybe you care the performance of functions that only run once, I don't.

@apocelipes
Copy link
Contributor Author

only run once.

Currently, but may be reused in the future.

Also, the new code is simple, we can do it better. fastfetch runs fastly is not only because it's wrote by c.

@apocelipes
Copy link
Contributor Author

I reused ffStrCopyN. Simpler code and better performance.

@CarterLi CarterLi merged commit 0284e4c into fastfetch-cli:dev Nov 10, 2024
16 checks passed
@apocelipes apocelipes deleted the optimize-createSubfolders branch November 10, 2024 10:38
CarterLi added a commit that referenced this pull request Nov 11, 2024
CarterLi added a commit that referenced this pull request Nov 11, 2024
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.

2 participants