Reduce CPU overhead in pathfinding, entity logic, and shadow rendering#1047
Open
starseed12345 wants to merge 1 commit intosmartcmd:mainfrom
Open
Reduce CPU overhead in pathfinding, entity logic, and shadow rendering#1047starseed12345 wants to merge 1 commit intosmartcmd:mainfrom
starseed12345 wants to merge 1 commit intosmartcmd:mainfrom
Conversation
- Cache shared_from_this() in serverAiStep - Reduce shared_ptr overhead in entities - Add shadow tile cache to optimize entity shadow rendering
Author
|
I'd also like it if someone could compare the performance results/cpu usage and let me know if i did any mistakes in the code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces several CPU overhead optimizations in pathfinding, entity logic, and entity shadow rendering.
The changes reduce repeated smart pointer operations and avoid redundant world lookups during shadow rendering.
Changes
Previous Behavior
serverAiStep repeatedly called shared_from_this() inside the function.
Entity logic performed unnecessary shared_ptr operations in hot paths.
Shadow rendering repeatedly queried Level::getTile and Level::getRawBrightness for the same blocks during a single frame.
These operations added unnecessary CPU overhead during entity updates and rendering.
Root Cause
Repeated shared_from_this() calls caused avoidable reference counting overhead.
Some entity rendering paths unnecessarily copied shared_ptr values.
Shadow rendering performed redundant world queries inside nested loops.
New Behavior
shared_from_this() is cached once in serverAiStep and reused.
Several entity functions reduce unnecessary shared_ptr overhead.
Shadow rendering caches tile ID and brightness values per block during a frame.
This reduces repeated computations and improves CPU efficiency in both entity logic and rendering.
Fix Implementation
Cached shared_from_this() at the beginning of serverAiStep and reused the result.
Reduced unnecessary shared_ptr copies in entity-related code paths.
Added shadowTileCache in EntityRenderDispatcher to cache:
tile ID
brightness
Introduced beginFrame() to clear the cache once per frame.
Updated renderShadow to reuse cached tile data instead of performing repeated world lookups.
AI Use Disclosure
AI was used to make the description of this pull request
Related Issues
None