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

Bit hacks to improve performance for 1.13 environmental lighting #4042

Conversation

kwvanderlinde
Copy link
Collaborator

@kwvanderlinde kwvanderlinde commented May 8, 2023

Identify the Bug or Feature request

Addresses #4031

Description of the Change

The LightingComposite.Blender implementations have been rewritten to avoid some expensive operations, and to make them more appealing to auto-vectorization on JDK 17.0.1. This also involved removing MAX_DARKNESS_BOOST_PER_128 as it ended up being 128 anyways and was just extra cruft.

Once the JVM optimizes, the same scenario as in the #4031 has these timings:

Timer ZoneRenderer.renderZone (66 elements)
    0.      60 ms  paintComponent
   36.      47 ms  lights
   38.      46 ms  renderLights:renderLightOverlay
   41.      35 ms  renderLightOverlay:drawLights
   42.      35 ms  renderLightOverlay:fillLight
   43.      10 ms  renderLightOverlay:drawBuffer

So mainly the improvement is coming from an improved ScreenBlender, while the ConstrainedBrightenBlender (represented in renderLightOverlay:drawBuffer) is just a little more consistent rather than seeing an large average improvement.

Possible Drawbacks

The code is less obvious now, which does make maintenace / browsing more difficult.

Performance is hardware dependent. While these changes shouldn't given a performance regression anywhere, it's hard to say for sure.

Documentation Notes

N/A

Release Notes

  • Improve environmental lighting performance.

This change is Reviewable

kwvanderlinde and others added 2 commits May 8, 2023 09:24
Ditch the rounding term, we didn't use it originally anyways

More hack to do final addition all at once instead of per-component

Remove obsolete no-op constant

Recognize that ScreenBlender is commutative, so we can avoid some of the masking by adding srcPixel at the end instead of dstPixel

Fix a comment

Reduce render timing threshold to nil

Add assembly printing to runtime configuration

Slight bit hacky tweak to ContrainedBrightenBlender to avoid need to call Math.min() as we are dealing with a special case

Clean up and document

Unreduce threshold
@cwisniew cwisniew merged commit 267fe34 into RPTools:release-1.13 May 9, 2023
4 checks passed
@kwvanderlinde kwvanderlinde deleted the performance/1.13-environmental-lighting-performance-bit-hacks branch May 9, 2023 04:17
@cwisniew cwisniew added the performance A performance or quality of life improvement label May 21, 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.

None yet

2 participants