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

Speed up SDL_FillRect[s] slightly #3290

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Closed

Speed up SDL_FillRect[s] slightly #3290

SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@SDLBugzilla
Copy link
Collaborator

SDLBugzilla commented Feb 11, 2021

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: HG 2.1
Reported for operating system, platform: macOS 10.13, x86_64

Comments on the original bug report:

On 2019-06-18 21:19:11 +0000, Jakub Stasiak wrote:

Created attachment 3831
Patch

This patch does the following:

  • Instead of SDL_FillRects calling SDL_FillRect in a loop the opposite happens – SDL_FillRect (a specific case) calls SDL_FillRects (a general case) with a count of 1
  • The switch/case block is moved out of the loop – it modifies the color once and stores the fill routine in a pointer which is then used throughout the loop

On my hardware (Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz) on Mac OS 10.13.6 the results of a test program (test.c, will attach) look like this:

Before the patch:

0.036588 us per SDL_FillRect
0.036908 us per SDL_FillRects with 1 rects (0.036908 us per rect)
0.071702 us per SDL_FillRects with 2 rects (0.035851 us per rect)
0.112443 us per SDL_FillRects with 3 rects (0.037481 us per rect)
0.139718 us per SDL_FillRects with 4 rects (0.034929 us per rect)
0.176768 us per SDL_FillRects with 5 rects (0.035354 us per rect)
0.210628 us per SDL_FillRects with 6 rects (0.035105 us per rect)
0.247989 us per SDL_FillRects with 7 rects (0.035427 us per rect)
0.280717 us per SDL_FillRects with 8 rects (0.035090 us per rect)
0.320848 us per SDL_FillRects with 9 rects (0.035650 us per rect)
0.347446 us per SDL_FillRects with 10 rects (0.034745 us per rect)
0.391779 us per SDL_FillRects with 11 rects (0.035616 us per rect)
0.405665 us per SDL_FillRects with 12 rects (0.033805 us per rect)
0.457827 us per SDL_FillRects with 13 rects (0.035217 us per rect)
0.477962 us per SDL_FillRects with 14 rects (0.034140 us per rect)
0.511664 us per SDL_FillRects with 15 rects (0.034111 us per rect)
0.545837 us per SDL_FillRects with 16 rects (0.034115 us per rect)
0.584130 us per SDL_FillRects with 17 rects (0.034361 us per rect)
0.605678 us per SDL_FillRects with 18 rects (0.033649 us per rect)
0.636722 us per SDL_FillRects with 19 rects (0.033512 us per rect)
0.665667 us per SDL_FillRects with 20 rects (0.033283 us per rect)

With the patch applied:

0.034671 us per SDL_FillRect
0.031070 us per SDL_FillRects with 1 rects (0.031070 us per rect)
0.062580 us per SDL_FillRects with 2 rects (0.031290 us per rect)
0.086069 us per SDL_FillRects with 3 rects (0.028690 us per rect)
0.110458 us per SDL_FillRects with 4 rects (0.027615 us per rect)
0.142235 us per SDL_FillRects with 5 rects (0.028447 us per rect)
0.168368 us per SDL_FillRects with 6 rects (0.028061 us per rect)
0.195460 us per SDL_FillRects with 7 rects (0.027923 us per rect)
0.226809 us per SDL_FillRects with 8 rects (0.028351 us per rect)
0.249367 us per SDL_FillRects with 9 rects (0.027707 us per rect)
0.270687 us per SDL_FillRects with 10 rects (0.027069 us per rect)
0.297366 us per SDL_FillRects with 11 rects (0.027033 us per rect)
0.321607 us per SDL_FillRects with 12 rects (0.026801 us per rect)
0.349090 us per SDL_FillRects with 13 rects (0.026853 us per rect)
0.372903 us per SDL_FillRects with 14 rects (0.026636 us per rect)
0.403684 us per SDL_FillRects with 15 rects (0.026912 us per rect)
0.423246 us per SDL_FillRects with 16 rects (0.026453 us per rect)
0.450657 us per SDL_FillRects with 17 rects (0.026509 us per rect)
0.476684 us per SDL_FillRects with 18 rects (0.026482 us per rect)
0.505739 us per SDL_FillRects with 19 rects (0.026618 us per rect)
0.531453 us per SDL_FillRects with 20 rects (0.026573 us per rect)

I went the store-the-fill-routine-in-a-function-pointer route as it seems to be working fine. If this is misguided and/or destroys performance on any hardware SDL targets please disregard this patch :)

On 2019-06-18 21:20:41 +0000, Jakub Stasiak wrote:

Created attachment 3832
test program

Test program was compiled with Apple LLVM version 10.0.0 (clang-1000.11.45.5), compile options: -O3

SDL compiled with default options.

On 2019-07-30 17:49:35 +0000, Ryan C. Gordon wrote:

(Sorry if you get several emails like this, we're marking a bunch of bugs.)

We're hoping to ship SDL 2.0.11 on a much shorter timeframe than we have historically done releases, so I'm starting to tag bugs we hope to have closed in this release cycle.

Note that this tag means we just intend to scrutinize this bug for the 2.0.11 release: we may fix it, reject it, or even push it back to a later release for now, but this helps give us both a goal and a wishlist for the next release.

If this bug has been quiet for a few months and you have new information (such as, "this is definitely still broken" or "this got fixed at some point"), please feel free to retest and/or add more notes to the bug.

--ryan.

On 2019-09-20 20:47:34 +0000, Ryan C. Gordon wrote:

We're changing how we do SDL release versions; now releases will be even numbers (2.0.10, 2.0.12, etc), and as soon as we tag a release, we'll move the internal version number to an odd number (2.0.12 ships, we tag the latest in revision control as 2.0.13 immediately, which will become 2.0.14 on release, etc).

As such, I'm moving the bugs tagged with target-2.0.11 to target 2.0.12. Sorry if you get a lot of email from this change!

Thanks,
--ryan.

On 2019-09-20 20:48:44 +0000, Ryan C. Gordon wrote:

We're changing how we do SDL release versions; now releases will be even numbers (2.0.10, 2.0.12, etc), and as soon as we tag a release, we'll move the internal version number to an odd number (2.0.12 ships, we tag the latest in revision control as 2.0.13 immediately, which will become 2.0.14 on release, etc).

As such, I'm moving the bugs tagged with target-2.0.11 to target 2.0.12. Sorry if you get a lot of email from this change!

Thanks,
--ryan.

On 2019-10-15 18:03:46 +0000, Ryan C. Gordon wrote:

This patch is now https://hg.libsdl.org/SDL/rev/1e6fddd82191, thanks!

--ryan.

@SDLBugzilla SDLBugzilla added the enhancement New feature or request label Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant