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

Preallocate buffers for use with LightingComposite.BlenderContext #4073

Conversation

kwvanderlinde
Copy link
Collaborator

@kwvanderlinde kwvanderlinde commented May 18, 2023

Identify the Bug or Feature request

Implements #4072

Description of the Change

Avoids allocating buffers in LightingComposite.BlenderContext.compose() as that method is called potentially many thousands of times per frame, especially with overlapping lights. The buffer size was chosen to hold 4096 pixels (16 KiB) in order to avoid chunked blending in most cases.

Another improvement was reducing the number of buffers from 3 to 2 since we don't need a separate output buffer.

From a performance perspective, the same situation as in #4042 and #4054 went from typically looking like this

Timer ZoneRenderer.renderZone (66 elements)
    0.      63 ms  paintComponent
   36.      48 ms  lights
   38.      48 ms  renderLights:renderLightOverlay
   41.      39 ms  renderLightOverlay:drawLights
   42.      39 ms  renderLightOverlay:fillLight

to

Timer ZoneRenderer.renderZone (66 elements)
    0.      45 ms  paintComponent
   36.      31 ms  lights
   38.      31 ms  renderLights:renderLightOverlay
   41.      23 ms  renderLightOverlay:drawLights
   42.      23 ms  renderLightOverlay:fillLight

So roughly 30% shaved off lights rendering as a result.

Possible Drawbacks

32 KiB of unreclaimable memory, and a guilty conscience ...

Documentation Notes

N/A

Release Notes

  • Improved lighting performance and memory usage.

This change is Reviewable

This avoids the overhead of allocating thousands of multi-KiB buffer every frame, only to deallocate each one almost immedaitely.
@cwisniew cwisniew added this pull request to the merge queue May 18, 2023
Merged via the queue into RPTools:develop with commit 0063879 May 18, 2023
@kwvanderlinde kwvanderlinde deleted the refactor/4072-preallocate-LightingComposite-buffers branch May 19, 2023 06:46
@cwisniew cwisniew added the feature Adding functionality that adds value label May 21, 2023
@Scubba
Copy link

Scubba commented Jun 13, 2023

Thanks, @kwvanderlinde great to see this!

@kwvanderlinde kwvanderlinde added performance A performance or quality of life improvement and removed feature Adding functionality that adds value labels Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance A performance or quality of life improvement
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

3 participants