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

FlxDrawQuadsItem and FlxDrawTrianglesItem are unoptimized, causing sprite draws to be expensive #3005

Closed
SomeGuyWhoLovesCoding opened this issue Jan 10, 2024 · 8 comments

Comments

@SomeGuyWhoLovesCoding
Copy link

  • Haxe version: 4.2.5
  • Flixel version: 5.2.2
  • OpenFL version: ?.?.?
  • Lime version: ?.?.?
  • Affected targets: Any?

(No code snippet)


Observed behavior:
When I draw about 2000 FlxSprite's with a width amd height of 112, it lags the game, which results to it being slower than openfl.display.Sprite.
Expected behavior:
What I want is for FlxSprite to not have expensive draw behaviors.

@SomeGuyWhoLovesCoding
Copy link
Author

So, I optimized all of the classes of flixel.graphics except FlxGraphicsShader since it's optimized well, I'll get the google drive link for it real quick

@SomeGuyWhoLovesCoding
Copy link
Author

So, I optimized all of the classes of flixel.graphics except FlxGraphicsShader since it's optimized well, I'll get the google drive link for it real quick

Here it is: https://drive.google.com/drive/folders/1qodl5Q5eYiz6hn7Z4ZrMHNbxEWhObWgL?usp=sharing

@Geokureli
Copy link
Member

If you want to propose changes to these classes do so by creating a fork of flixel, making a feature branch with the changes and creating a PR. If youre new to git and github then check out this contribution guide

@DigiEggz
Copy link
Contributor

So, I optimized all of the classes of flixel.graphics except FlxGraphicsShader since it's optimized well, I'll get the google drive link for it real quick

I'd love to see what changes you made as well in a pull request. Thanks for contributing!

@helpmeiguess
Copy link

So, I optimized all of the classes of flixel.graphics except FlxGraphicsShader since it's optimized well, I'll get the google drive link for it real quick

thats pretty cool, i just checked it out, and the files are all watermarked with "@author Zaphod". i cant find any association from you with that name, even from the gmail account the files were uploaded by. who is zaphod?

@giuppe
Copy link
Contributor

giuppe commented Jan 13, 2024

I'd also love to see:

  • what are you measuring;
  • how are you measuring it;
  • for which target(hxcpp, hl, html5 etc.) and architecture:

before and after the changes.

I tried FlxBunnyMark (target: hxcpp on windows) and I measured a worse performance:

With changes:
with changes

Without changes:
Without changes


I have some things to point out about the code you posted. I found these changes:

alphas.splice(0, alphas.length);
if (colorMultipliers != null)
	colorMultipliers.splice(0, colorMultipliers.length);
if (colorOffsets != null)
	colorOffsets.splice(0, colorOffsets.length);

that you changed as:

alphas = colorMultipliers = colorOffsets = [];

this will break many things, as arrays are stored as reference so they become the same array (as you can see here: https://try.haxe.org/#1201922d). Also you are creating a new array each time, this could be impactful on C++ targets.


This:

return Std.int(position / elementsPerTile);

became:

return Std.int(position * Math.pow(elementsPerTile, -1));

While I'm sure Math.pow() with a negative exponent is well optimized on most targets, I would like to see the data that supports that it is faster than a division in the general case.


This:

colorMultipliers.push(1);
colorMultipliers.push(1);
colorMultipliers.push(1);

became:

while (colorMultipliers.length < 3) colorMultipliers.push(1);

Also in this case, I would like to see the data that supports the change: the original code is an unrolled loop, and this is usually faster for smaller code: even compilers automatically try to unroll smaller loops.


This code:

drawCalls++;

became:

drawCalls += 1;

This does really nothing, as the Haxe code is transpiled to several different languages and then optimized for the target: for example in JS in both cases it's transpiled to the same code, as you can see here: https://try.haxe.org/#cb126443


I couldn't find any other significant change, so idk, maybe I forgot to include some files? Or am I seeing a draft version and you have already changed/fixed it?

@giuppe
Copy link
Contributor

giuppe commented Jan 13, 2024

who is zaphod?

The original author of HaxeFlixel.

@Geokureli
Copy link
Member

Geokureli commented Jan 22, 2024

@SomeGuyWhoLovesCoding, I'm closing this now as it seems to be dead, I welcome you to try this again, but when/if you do, please remember to be clear about what problems you are trying to solve, how you observed these problems, and how you intend to solve these problems. Please use the contribution guide so that we can properly analyze and discuss each change.

You my reopen this issue or create another, when that time comes, but if you want to submit changes it must be in a pull request

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

No branches or pull requests

5 participants