Skip to content

Conversation

SpexGuy
Copy link
Contributor

@SpexGuy SpexGuy commented Jan 11, 2017

Explanation:
DefaultShader#canRender(..) used to call combineAttributes(..) on the renderable, and then only use the mask. combineAttributes(..) is very expensive (around O(n2log(n)) where n is the number of unique attributes, because it sorts after adding each attribute). But all the function really needs is the combined mask, and since we keep the masks for both Attributes objects around anyway we can get it with just a bitwise or.

Our game uses a large number of ModelInstances with about 15 shaders, which meant every time it added a renderable to the batch (several times per ModelInstance) it would have to iterate ~7 shaders on average and combineAttributes(..) for each one, which was a major hit to pre-render time. Implementing this change brought the frame render time on our min spec phone from 40ms to 30ms, a major performance gain that made the game playable.

@xoppa xoppa merged commit a7134f3 into libgdx:master Jan 11, 2017
@xoppa
Copy link
Member

xoppa commented Jan 11, 2017

Thanks!

@SpexGuy SpexGuy deleted the bitwiseIsBetter branch January 12, 2017 20:23
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