-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
Use HasColorKey instead of GetColorKey in pgSurface_Blit #2835
Use HasColorKey instead of GetColorKey in pgSurface_Blit #2835
Conversation
This routine doesn't use the value of GetColorKey, it just wants to know whether the surface has one. Internally, this was setting a bunch of SDL errors ("surf doesn't have colorkey"-esque), which became much more expensive in SDL 2.29.3 because of a new logging feature. Therefore lets replace it with HasColorKey (a newer function, the code was originally written before this existed). This fixes the performance regression here and even makes the performance slightly better than it was before, at least in my test scenario. Credit to itzpr for narrowing this down to SDL_GetColorKey
Test script: import random
import time
import pygame
random.seed(36)
width = 600
height = 400
screen = pygame.Surface((width, height))
def make_particle():
p_surf = pygame.Surface((5,5))
p_surf.fill((random.randint(0,255), random.randint(0,255), random.randint(0,255)))
return (p_surf, (random.randint(0, width), random.randint(0, height)))
particles = [make_particle() for _ in range(1000000)]
start = time.time()
screen.fblits(particles)
print(time.time() - start) Results:
|
An example of how the issue ( #2821 ) isn't fully fixed by this PR-- If you take the previous example and swap out the line defining On 2.4.1 it's 0.30 seconds, on main it's 1.60 seconds, and on this PR it's 0.63 seconds. So an improvement, but the SDL_GetColorKey in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About this, if SDL can do something about SDL_GetColorkey's perf we're good, otherwise could we implement our own function for that? I know SDL_Surface.map is private and it wouldn't be the best practice but what woud be the alternatives? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the PR! 🎉
This routine doesn't use the value of GetColorKey, it just wants to know whether the surface has one.
Internally, this was setting a bunch of SDL errors ("surf doesn't have colorkey"-esque), which became much more expensive in SDL 2.29.3 because of a new logging feature.
Therefore lets replace it with HasColorKey (a newer function, the code was originally written before this existed). This fixes the performance regression here and even makes the performance slightly better than it was before, at least in my test scenario.
Credit to @itzpr3d4t0r for narrowing this down to SDL_GetColorKey
Relevant to #2821