Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize ImageLoaderSVG::create_image_from_utf8_buffer #137

Conversation

beru
Copy link
Contributor

@beru beru commented Oct 3, 2024

This PR optimizes ImageLoaderSVG::create_image_from_utf8_buffer method.

I built the engine with the following command.

python -m SCons platform=windows target=editor debug_symbols=yes

And profiled CPU usage with Microsoft Visual Studio's Perfromance Profiler by launching redot.windows.editor.x86_64.exe file. A little bif of performance improvement can be confirmed.

(Tested with AMD Ryzen 9 7900X processor)

Checked version ImageLoaderSVG::create_image_from_utf8_buffer CPU usage (%)
Before (9a49cab) 2.59
After 1.43

modules/svg/image_loader_svg.cpp Outdated Show resolved Hide resolved
modules/svg/image_loader_svg.cpp Outdated Show resolved Hide resolved
@Spartan322
Copy link
Member

Is this still being worked on?

@beru
Copy link
Contributor Author

beru commented Oct 14, 2024

@Spartan322

Is this still being worked on?

If a further udpate is requested from reviewers, I will consider it. Maybe adding a lot of lines for the optimized code in ImageLoaderSVG::create_image_from_utf8_buffer method reduces code readability so separating the code by adding rgba2bgra function might be a good idea. What do you think?

@Spartan322
Copy link
Member

Spartan322 commented Oct 14, 2024

Well the most notable thing is you need to squash the commits, and yeah making it more readable would definitely be desirable, also does this have a corresponding Godot PR or proposal? And what is your opinion on having submitting this upstream to Godot? (presuming it hasn't already been tried)

@beru
Copy link
Contributor Author

beru commented Oct 15, 2024

@Spartan322

Well the most notable thing is you need to squash the commits

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/about-pull-request-merges#squash-and-merge-your-commits

My understanding is that maintainers who have rights to merge PRs can choose Squash and merge if they want to squash commits and merge single squashed commit into the target branch (Redot-Engine:master). If maintainers/reviewers still prefer to review single merged commit with this PR, I'd squash them at my side.

making it more readable would definitely be desirable

Then I will create a function to isolate the optimized code and call the newly created function from ImageLoaderSVG::create_image_from_utf8_buffer method.

does this have a corresponding Godot PR or proposal?

I still haven't created a PR on https://github.com/godotengine/godot project.

And what is your opinion on having submitting this upstream to Godot? (presuming it hasn't already been tried)

I'm not really sure if it's absolutely necessary but if maintainers/reviewers want it to happen, I'll open a PR (or an issue) on the original project.

Please be aware that merging this PR doesn't benefit users who use Pre-Built xxdot Engine Binaries. (The reason is written on #137 (comment))

@Spartan322
Copy link
Member

Spartan322 commented Oct 15, 2024

My understanding is that maintainers who have rights to merge PRs can choose Squash and merge if they want to squash commits and merge single squashed commit into the target branch (Redot-Engine:master).

Githubs documentation is full of problems and contradicts itself regularly, as well what that actually does is eliminates references to the PR and the original commit which its own form of pain, its not just review that's easier, but also it makes the management of history and reverts easier, plus its the only way to be consistent, Github's PR squash behavior is functionally useless and unusable for any real git workflow. We follow Godot's PR workflow which requires you to squash your commits anyway.

I'm not really sure if it's absolutely necessary but if maintainers/reviewers want it to happen, I'll open a PR (or an issue) on the original project.

Unless you have an opposition to doing so, its usually preferable to push things that haven't been submitted to Godot there first so that we can minimize merge conflicts when we merge back from upstream, we want to focus more on stalled, abandoned, and rejected PRs (and/or proposals) over specifically just being distinct from Godot by having specific distinct contributors.

Please be aware that merging this PR doesn't benefit users who use Pre-Built xxdot Engine Binaries.

Well yeah that's not really a big deal, Godot, and thus Redot, has plenty of things that aren't produced in the pre-built binaries anyway, some specific workflows (like encrypted pcks) already require compiling it yourself anyhow.

@beru
Copy link
Contributor Author

beru commented Oct 15, 2024

Githubs documentation is full of problems and contradicts itself regularly, as well what that actually does is eliminates references to the PR and the original commit which its own form of pain, its not just review that's easier, but also it makes the management of history and reverts easier, plus its the only way to be consistent, Github's PR squash behavior is functionally useless and unusable for any real git workflow. We follow Godot's PR workflow which requires you to squash your commits anyway.

Wow, I didn't know GitHub has those issues. They must have been frustrating to some users.

Unless you have an opposition to doing so, its usually preferable to push things that haven't been submitted to Godot there first so that we can minimize merge conflicts when we merge back from upstream, we want to focus more on stalled, abandoned, and rejected PRs (and/or proposals) over specifically just being distinct from Godot by having specific distinct contributors.

It's totally fine for me to do so. It's just I wasn't aware it's the preferable way. So I'll close this PR and create an issue (and a PR) to the original project. If the PR on the original project wouldn't be merged after several years, I might reopen this PR.

Well yeah that's not really a big deal, Godot, and thus Redot, has plenty of things that aren't produced in the pre-built binaries anyway, some specific workflows (like encrypted pcks) already require compiling it yourself anyhow.

Glad to hear that. Thank you for explaining a lot of things to a new comer.

@beru beru closed this Oct 15, 2024
@Spartan322
Copy link
Member

Spartan322 commented Oct 15, 2024

There's no need to close this PR, as there is potential for it to still be considered here, we just want to see what happens when submitted to Godot first for things that haven't been there yet, (given the PR author is fine with it going upstream) if it takes too long (we'd definitely consider it well before a few years pass, likely before a few months pass) or gets rejected, we're still likely to consider this, also I'm not entirely sure this would need a Godot proposal, I'm pretty sure you can just submit a PR for it.

@beru beru reopened this Oct 15, 2024
@beru beru force-pushed the opt_ImageLoaderSVG__create_image_from_utf8_buffer branch 4 times, most recently from 1b5f96b to 10fb526 Compare October 19, 2024 03:35
@beru
Copy link
Contributor Author

beru commented Oct 19, 2024

I've just opened a PR on the Godot project.
godotengine/godot#98329

@beru beru force-pushed the opt_ImageLoaderSVG__create_image_from_utf8_buffer branch from 10fb526 to 141f75e Compare October 19, 2024 05:02
@SkogiB
Copy link
Contributor

SkogiB commented Oct 23, 2024

Upstream approved the PR but still waiting on them to merge. We don't have a nailed down timeline we'll wait for Godot to merge stuff like this, as we can't have our contributors waiting 3 months on Godot, but we'll keep an eye on it when we have time and discuss when to let Godot be lame and pull the trigger on our own.

@beru
Copy link
Contributor Author

beru commented Oct 24, 2024

godotengine/godot#98329 has been merged so I'll close this one.
Thank you for helpful comments and suggestions.

@beru beru closed this Oct 24, 2024
@beru beru deleted the opt_ImageLoaderSVG__create_image_from_utf8_buffer branch October 24, 2024 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants