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

perf: remove unnecessary event callbacks #3076

Merged
merged 5 commits into from
Nov 8, 2024

Conversation

dudantas
Copy link
Member

@dudantas dudantas commented Nov 7, 2024

Description

Removed Lua callbacks from MonsterType of various monsters. These callbacks were empty, which meant the functions were still being "called" by the monsters without performing any action, creating a significant performance bottleneck.

Removed the onHear event callback, which had a significant impact on the server and was not used anywhere. It executed the onHear callback for each spectator, causing an unnecessary overload without any real benefit, especially as we have other methods to check for these events.

Additionally, the monsterOnSpawn event callback was removed and replaced with MonsterType::onSpawn, which is much more efficient since it only needs to be declared in the script for each monster that actually uses it.

Finally, the way setRewardBoss was handled was improved. Previously, it was executed in an onSpawn event callback, but now it is done directly during the parsing of each monster script, marking them as reward bosses at the time of script loading, improving efficiency.

image

Behaviour

Actual

  • Empty callbacks were being called by monsters without doing anything, causing a performance loss.
  • onHear was executed for every spectator, generating unnecessary server overload.
  • setRewardBoss was done through the onSpawn event callback, which was inefficient.

Expected

  • Remove empty callbacks to avoid unnecessary calls and improve performance.
  • Remove the onHear event callback to reduce overload and improve server efficiency.
  • Use MonsterType::onSpawn to replace monsterOnSpawn.
  • Set setRewardBoss directly during the reading of the monster scripts to avoid overhead during spawn.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested

Tests were conducted to verify the effectiveness of the changes in terms of monster performance and behavior.

  • Test A: Removal of empty callbacks and monitoring of performance.
  • Test B: Verification of monster behavior with MonsterType::onSpawn.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I checked the PR checks reports
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

improve: remove empty monsters callbacks and register setReward in monster lib
@dudantas dudantas force-pushed the dudantas/perf-remove-unecessary-event-callbacks branch from aaf74b1 to ddf011d Compare November 7, 2024 21:55
Copy link

sonarqubecloud bot commented Nov 8, 2024

@dudantas dudantas linked an issue Nov 8, 2024 that may be closed by this pull request
@dudantas dudantas merged commit ceace16 into main Nov 8, 2024
43 checks passed
@dudantas dudantas deleted the dudantas/perf-remove-unecessary-event-callbacks branch November 8, 2024 04:44
dudantas added a commit that referenced this pull request Dec 21, 2024
Fixes bugs introduced here:
#3076

By mistake I removed the onSpawn from the hazard and didn't realize it.
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.

Performance: rework in Eventcallback "creatureOnHear"
3 participants