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

Make add_msg_debug and variants a macro. #69581

Merged
merged 11 commits into from
Jan 24, 2024

Conversation

prharvey
Copy link
Contributor

Summary

None

Purpose of change

Parameters to add_msg_debug can be expensive, notably monster::name which shows up on profiles as taking up a few % of execution time.

Describe the solution

Turn add_msg_debug into a macro, which allows parameters to be evaluated only if the debug flag is actually enabled.

Testing

Verified that debug messages were still working as intended.

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` astyled astyled PR, label is assigned by github actions Code: Tests Measurement, self-control, statistics, balancing. json-styled JSON lint passed, label assigned by github actions Translation I18n Code: Tooling Tooling that is not part of the main game but is part of the repo. labels Nov 20, 2023
@github-actions github-actions bot added BasicBuildPassed This PR builds correctly, label assigned by github actions astyled astyled PR, label is assigned by github actions NPC / Factions NPCs, AI, Speech, Factions, Ownership Map / Mapgen Overmap, Mapgen, Map extras, Map display Monsters Monsters both friendly and unfriendly. and removed astyled astyled PR, label is assigned by github actions labels Nov 20, 2023
@prharvey prharvey changed the title Make add_msg_debug a macro. Make add_msg_debug and variants a macro. Nov 20, 2023
@prharvey prharvey marked this pull request as ready for review November 21, 2023 03:18
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-requesting reviews from non-collaborators: @jbytheway

@Maleclypse Maleclypse requested a review from akrieger November 21, 2023 03:48
@github-actions github-actions bot added <Documentation> Design documents, internal info, guides and help. Info / User Interface Game - player communication, menus, etc. Code: Build Issues regarding different builds and build environments [JSON] Changes (can be) made in JSON Items: Magazines Ammo holding items and objects. Bionics CBM (Compact Bionic Modules) Vehicles Vehicles, parts, mechanics & interactions Items: Food / Vitamins Comestibles and drinks Crafting / Construction / Recipes Includes: Uncrafting / Disassembling Spawn Creatures, items, vehicles, locations appearing on map Mutations / Traits / Professions/ Hobbies Mutations / Traits / Professions/ Hobbies Fields / Furniture / Terrain / Traps Objects that are part of the map or its features. [Markdown] Markdown issues and PRs labels Nov 24, 2023
@prharvey
Copy link
Contributor Author

Since this is perf, can we see the before/after profile?

Since this has small effects everywhere it's hard to demonstrate directly, but I can show it indirectly by looking at monster::name

Before:
name

After:
Screenshot 2023-11-23 183230

Although it isn't the few % compared to master mentioned in the summary, as I first noticed this problem on my local version which has #69574 and #69198 on it (well, not the second one directly, since I'm rewriting that, but you get the idea), and those problems are dominating perf at the moment. Once they are in it is closer to 2% on just this function.

@akrieger
Copy link
Member

If trying to demonstrate small-but-broad improvement, a good way to show it is to take several traces of a consistent time period (eg. wait the same 6 hours at a location) before & after to show overall runtime improvement. Note that I've found the profiler to have consistent variation of +-5% so improvements less than that may be lost to noise.

@prharvey
Copy link
Contributor Author

prharvey commented Nov 24, 2023

If trying to demonstrate small-but-broad improvement, a good way to show it is to take several traces of a consistent time period (eg. wait the same 6 hours at a location) before & after to show overall runtime improvement. Note that I've found the profiler to have consistent variation of +-5% so improvements less than that may be lost to noise.

This is actually why I mentioned it was hard to show directly currently. Against current master the performance is dominated by much larger problems so it is hard for this to stand out; right now the debug messages not being in a define is more of a code smell than a true performance issue.

That said, when the other changes I plan to make actually land, this will make a noticeable difference. Or at least a more convincing difference when you can actually see functions disappear from the flame graph. If there is any skepticism about the improvement, I'm fine with waiting to merge this until those other things land as well.

I was originally going to get to this optimization much later anyways, but it was pretty easy to do independently and I was reminded of it by a recent NPC AI PR that was adding these extensively.

@akrieger
Copy link
Member

Ah, ok. Well code looks fine to me and I understand the reasoning for it.

@akrieger
Copy link
Member

I think it'll also seriously matter for #69623, I'm going to patch that and wait at refugee center and see how much it hurts.

@kevingranade
Copy link
Member

If there is any skepticism about the improvement, I'm fine with waiting to merge this until those other things land as well.
I'm very much in the wait and see camp here, yes it's potentially needless overhead, but also it's overhead that is going to happen anyway if we are running with debug messages on, and macros are gross. (This is not a criticism of you, I'm not aware of a better way to make this happen either)

@prharvey
Copy link
Contributor Author

If there is any skepticism about the improvement, I'm fine with waiting to merge this until those other things land as well. I'm very much in the wait and see camp here, yes it's potentially needless overhead, but also it's overhead that is going to happen anyway if we are running with debug messages on, and macros are gross. (This is not a criticism of you, I'm not aware of a better way to make this happen either)

While I can't solve the issues with macros, the majority of users will be playing the game with debug messages off. So I think it is still important to remove overhead in this case.

Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Please do not bump or comment on this issue unless you are actively working on it. Stale issues, and stale issues that are closed are still considered.

@github-actions github-actions bot added the stale Closed for lack of activity, but still valid. label Dec 25, 2023
@kevingranade kevingranade added Code: Performance Performance boosting code (CPU, memory, etc.) (P5 - Long-term) Long-term WIP, may stay on the list for a while. labels Dec 25, 2023
@Maleclypse Maleclypse removed the stale Closed for lack of activity, but still valid. label Dec 31, 2023
@github-actions github-actions bot added NPC / Factions NPCs, AI, Speech, Factions, Ownership Map / Mapgen Overmap, Mapgen, Map extras, Map display Monsters Monsters both friendly and unfriendly. Code: Tooling Tooling that is not part of the main game but is part of the repo. json-styled JSON lint passed, label assigned by github actions labels Jan 1, 2024
@Maleclypse Maleclypse merged commit de8a47f into CleverRaven:master Jan 24, 2024
20 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` Code: Performance Performance boosting code (CPU, memory, etc.) Code: Tests Measurement, self-control, statistics, balancing. Code: Tooling Tooling that is not part of the main game but is part of the repo. Info / User Interface Game - player communication, menus, etc. json-styled JSON lint passed, label assigned by github actions Map / Mapgen Overmap, Mapgen, Map extras, Map display Monsters Monsters both friendly and unfriendly. NPC / Factions NPCs, AI, Speech, Factions, Ownership (P5 - Long-term) Long-term WIP, may stay on the list for a while. Translation I18n
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants