Skip to content

Conversation

@Xomikadze92
Copy link

@Xomikadze92 Xomikadze92 commented Nov 13, 2025

Summary

Performance "Fixing an unnecessary call to the liquid container inspection function when creating solid objects"

Purpose of change

Remove unnecessary calls to functions for creating objects and others

Describe the solution

When creating items, regardless of the aggregate state, a check (check_eligible_containers_for_crafting) is run to determine whether they will fit or not. At the beginning of the check, items and by-products are "created". And then each unit of production is checked to see if it is liquid. I have implemented a function that immediately checks the final result of crafting, since it is known in advance. And if the result is liquids, then the container check is started in full as before, and if there are no liquids, then the check is not necessary.

Describe alternatives you've considered

It may be worth redoing the check_eligible_containers_for_crafting check to check all the liquids at once, rather than creating them.

Testing

Created item that have only non-liquid results, which have only liquid results and mixed results.

Additional context

@github-actions github-actions bot added Info / User Interface Game - player communication, menus, etc. Crafting / Construction / Recipes Includes: Uncrafting / Disassembling [C++] Changes (can be) made in C++. Previously named `Code` new contributor labels Nov 13, 2025
Xomikadze92 and others added 4 commits November 13, 2025 07:33
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions github-actions bot added json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Nov 13, 2025
@github-actions github-actions bot added Code: Performance Performance boosting code (CPU, memory, etc.) BasicBuildPassed This PR builds correctly, label assigned by github actions labels Nov 13, 2025
@kevingranade
Copy link
Member

If this is performance oriented it needs some performance testing like a use case where it's spending a lot of time and before/after profiles showing it was meaningfully improved.

@Xomikadze92
Copy link
Author

Xomikadze92 commented Nov 13, 2025

@kevingranade yes, that's a fair point. I did a run-time test a few minutes ago. Actually, I'm not sure if I did it right, but still the result is there.
I wrapped the code:

} else if( action == "CONFIRM" ) {
auto start = std::chrono::high_resolution_block::now();
	// code
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
debugmsg( "Run time: %s ", duration.count() );
}

And the following results came out about creating things in batches of 50.
Before modification:
24755, 21659, 21303 - 50 acidic electrolyte paste
33313, 30830, 28252, 30354, 28742, 23036, 32212, 27969, 31559 - 50 makeshift bandage
41023, 40675, 42488 - 50 boiled makeshift bandage
35545, 37412, 34029 - 50 clean water
After modification:
47, 36, 35 - 50 acidic electrolyte paste
33, 31, 30, 29, 31, 29, 21, 29, 28 - 50 makeshift bandage
42049, 41429, 42133 - 50 boiled makeshift bandage
36644, 33609, 33624 - 50 clean water

Nothing much has changed for liquid and mixed results, but for completely non-liquid results, the difference is very noticeable. If there is another method like monjo inside VS Code to check performance, then please tell me how to do it.

@github-actions
Copy link
Contributor

Hi @Xomikadze92, welcome to CleverRaven! We see that this is your first time commenting here. Check out how development works and be sure to follow the code of conduct! We hope to see you around!

@kevingranade
Copy link
Member

If I'm reading this correctly the overhead we're talking about here is less than one ms per item in the batch, and it only occurs once when a recipe is completed? I'm skeptical that's even noticeable, especially at the end of a many-turn crafting process.

@Xomikadze92
Copy link
Author

Yes, that's right, the wound is really very small, perhaps it is more noticeable on a weaker PC configuration. But I've learned that in any case, it's better to get rid of unnecessary function calls. Also, this check only works from the crafting menu, but in my opinion it should work the same way when we interrupted crafting and resumed it. So I would like to further optimize the operation of this functionality.

@github-actions
Copy link
Contributor

Hi @Xomikadze92, welcome to CleverRaven! We see that this is your first time commenting here. Check out how development works and be sure to follow the code of conduct! We hope to see you around!

@CLIDragon
Copy link
Contributor

What is the performance impact on creating 50 batches of salt using the lye + hydrochloric acid recipe, so ~7000 individual items?

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.) Crafting / Construction / Recipes Includes: Uncrafting / Disassembling Info / User Interface Game - player communication, menus, etc. json-styled JSON lint passed, label assigned by github actions new contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants