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

Reserve space for vectors before allocating in a loop. #77728

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CLIDragon
Copy link
Contributor

Summary

None

Purpose of change

Pre-allocating saves doing multiple allocations when we know exactly what size structure we need.

Describe the solution

Manually search through the code base for all push_back and reserve space if applicable.

Describe alternatives you've considered

clang-tidy has a lint for this, but I don't really understand how it's configured for this project plus it's configured for linux. It was easier to do a find than to try and mess with the build settings.

Testing

Ran the game before and after. No noticeable performance changes. There are no functionality changes, so nothing should break.

Additional context

@github-actions github-actions bot added NPC / Factions NPCs, AI, Speech, Factions, Ownership Info / User Interface Game - player communication, menus, etc. Vehicles Vehicles, parts, mechanics & interactions Mutations / Traits / Professions/ Hobbies Mutations / Traits / Professions/ Hobbies [C++] Changes (can be) made in C++. Previously named `Code` Martial Arts Arts, Techniques, weapons and anything touching martial arts. json-styled JSON lint passed, label assigned by github actions labels Nov 10, 2024
@PatrikLundell
Copy link
Contributor

You'd probably want to do the same for the vile emplace_back the tools demand we replace push_back with (since you didn't change those lines it may not demand you to change these, but you touched the file they're in, so you may be at risk).

"Vile" because the damned thing doesn't warn you when you feed it the wrong type, but instead barfs out a horrible mess of usages during compilation of emplace_back for you to sift through until you eventually find the one it doesn't like.

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Nov 10, 2024
@github-actions github-actions bot added Missions Quests and missions Map / Mapgen Overmap, Mapgen, Map extras, Map display Monsters Monsters both friendly and unfriendly. Scenarios New Scenarios, balancing, bugs with scenarios Character / World Generation Issues and enhancements concerning stages of creating a character or a world Player Faction Base / Camp All about the player faction base/camp/site Game: Achievements / Conducts / Scores Player goals and how they are tracked. Items: Armor / Clothing Armor and clothing labels Nov 11, 2024
Pre-allocating saves doing multiple allocations when we know exactly
what size structure we need.
@github-actions github-actions bot added astyled astyled PR, label is assigned by github actions and removed BasicBuildPassed This PR builds correctly, label assigned by github actions labels Nov 11, 2024
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 [C++] Changes (can be) made in C++. Previously named `Code` Character / World Generation Issues and enhancements concerning stages of creating a character or a world Game: Achievements / Conducts / Scores Player goals and how they are tracked. Info / User Interface Game - player communication, menus, etc. Items: Armor / Clothing Armor and clothing json-styled JSON lint passed, label assigned by github actions Map / Mapgen Overmap, Mapgen, Map extras, Map display Martial Arts Arts, Techniques, weapons and anything touching martial arts. Missions Quests and missions Monsters Monsters both friendly and unfriendly. Mutations / Traits / Professions/ Hobbies Mutations / Traits / Professions/ Hobbies NPC / Factions NPCs, AI, Speech, Factions, Ownership Player Faction Base / Camp All about the player faction base/camp/site Scenarios New Scenarios, balancing, bugs with scenarios Vehicles Vehicles, parts, mechanics & interactions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants