Skip to content

Commit

Permalink
UI/Solve performance fix for large tables. (#287)
Browse files Browse the repository at this point in the history
VS diagnostics reported a lot of CPU time was spent in this `.Any` call,
which happened because `!row.hierarchyEnabled` only short-circuited one
of the embedded `.Any` calls.

After fixing the parentheses, the solve-time on a 1400-recipe sheet went
from significant (~900 ms) to almost unnoticeable (~200 ms)

I also updated the style to error if && and || are mixed without
parentheses again.
  • Loading branch information
shpaass authored Sep 14, 2024
2 parents 9a42bee + b3782ec commit 007ff60
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dotnet_style_predefined_type_for_member_access = true:suggestion
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:none
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:none
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:none
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:error
dotnet_style_parentheses_in_other_operators = always_for_clarity:none
# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
Expand Down
3 changes: 2 additions & 1 deletion Yafc.Model/Model/ProductionTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ private static void AddLinkCoef(Constraint cst, Variable var, ProductionLink lin
/// <param name="goods">The <see cref="Goods"/> that might have its link removed.</param>
/// <returns><see langword="true"/> if the link should be preserved, or <see langword="false"/> if it is ok to delete the link.</returns>
private bool HasDisabledRecipeReferencing(Goods goods)
=> GetAllRecipes().Any(row => !row.hierarchyEnabled && row.recipe.ingredients.Any(i => i.goods == goods) || row.recipe.products.Any(p => p.goods == goods) || row.fuel == goods);
=> GetAllRecipes().Any(row => !row.hierarchyEnabled
&& (row.fuel == goods || row.recipe.ingredients.Any(i => i.goods == goods) || row.recipe.products.Any(p => p.goods == goods)));

private bool CheckBuiltCountExceeded() {
bool builtCountExceeded = false;
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Date:
- Fixed recipes now become accessible when their crafter does.
Internal changes:
- Allow tooltips to be displayed when hovering over radio buttons.
- Require parentheses when mixing && and || in the same expression.
----------------------------------------------------------------------------------------------------------------------
Version: 0.9.1
Date: September 8th 2024
Expand Down

0 comments on commit 007ff60

Please sign in to comment.