Skip to content

perf improvement attempts for OpenGL.c - #463

Closed
hilga007 wants to merge 1 commit into
fastfetch-cli:devfrom
hilga007:patch-2
Closed

hilga007 wants to merge 1 commit into
fastfetch-cli:devfrom
hilga007:patch-2

Conversation

@hilga007

Copy link
Copy Markdown

avoiding unnecessary memory allocations and string copying

 avoiding unnecessary memory allocations and string copying
Comment thread src/modules/opengl.c
Comment on lines -11 to -14
ffStrbufInit(&result.version);
ffStrbufInit(&result.renderer);
ffStrbufInit(&result.vendor);
ffStrbufInit(&result.slv);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If the strbufs aren't initialized, ffDetectOpenGL will write data in random memory places, which most probably will cause a seg fault

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The reason that the pipeline doesn't fail is that the GitHub VMs don't have OpenGL support

Comment thread src/modules/opengl.c
Comment on lines +26 to +33
FFformatarg formatArgs[FF_OPENGL_NUM_FORMAT_ARGS] = {
{ FF_FORMAT_ARG_TYPE_STRBUF, &result.version },
{ FF_FORMAT_ARG_TYPE_STRBUF, &result.renderer },
{ FF_FORMAT_ARG_TYPE_STRBUF, &result.vendor },
{ FF_FORMAT_ARG_TYPE_STRBUF, &result.slv }
};

ffStrbufDestroy(&result.version);
ffStrbufDestroy(&result.renderer);
ffStrbufDestroy(&result.vendor);
ffStrbufDestroy(&result.slv);
ffPrintFormat(instance, FF_OPENGL_MODULE_NAME, 0, &instance->config.openGL, FF_OPENGL_NUM_FORMAT_ARGS, formatArgs);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why? The compiled assembly will be the same

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Again - did not mean to submit to you - the "why" is just "this is what I have been learning w/o a class and w/o a university and wanted to apply a small change based on best practice"

I guess so maybe what you are saying is that "it does not matter which path is taken, so long as the destination is reached?" Whereas that is the opposite of what I had bothered to learn, which is why this change had been made.

"Conformance is performance" was one of the small sayings.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The example is similar to the following:

void do_something(int);

//My Version
do_something(5);

//Your version
int a = 5;
do_something(a);

Compiled they are the same, so lets only talk about the code style. Mine is more simple, and still readable, so it is the better solution here. (In my opionion, we are at a point where personal opionion does make the difference)

@hilga007 hilga007 May 29, 2023 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

And experience! Your experience makes it make sense! Thank you!!! As they say "real world experience" makes a difference over "textbook experience" :) :) (time to add to my notes here...)

Sorry for the panic attack.....
Again I am very new with this. Only reading C99 books when young, and then 2 months of a course + textbook.

@UnixUserDev UnixUserDev mentioned this pull request Oct 16, 2026
5 tasks done
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