Cache computed values in `Options.cs`
See original GitHub issueThere’s a couple of methods in Options.cs
that are likely being called from hotpath - I assume return values will get cached by JIT or something, but it wouldn’t harm to just cache the values when option values change…
_Originally posted by @aubergine10 in https://github.com/CitiesSkylinesMods/TMPE/pull/1512#discussion_r842025062_
getRecklessDriverModulo()
This converts reckless driver drop-down value in to a modulo. We should calculate it whenever reckless dirver option changes and cache result in an int
field.
Additionally, code intent can be clarified with switch expression:
internal static int RecklessDriverModulo(RecklessDrivers level) => level switch
{
RecklessDrivers.PathOfEvil => 10,
RecklessDrivers.RushHour => 20,
RecklessDrivers.MinorComplaints => 50,
RecklessDrivers.HolyCity => 10000,
_ => 10000,
};
IsDynamicLaneSelectionActive()
This can be invoked whenever the associated options (Advanced Vehicle AI checkbox and DLS slider) change and result cached in a bool
field.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
c# - Cached Property: Easier way?
I have a object with properties that are expensive to compute, so they are only calculated on first access and then cached. private...
Read more >side effects for caching in @computed values with existing ...
I'm new to mobx and am trying to implement caching for my application's state using @computed values but am running into an error....
Read more >Options pattern in ASP.NET Core
The IOptionsMonitorCache<TOptions> invalidates options instances in the monitor so that the value is recomputed (TryRemove). Values can be ...
Read more >Reading and writing data to the cache
You can read and write cache data using GraphQL queries that are similar (or even ... It resembles readQuery , except that it...
Read more >Add caching with reactivity to an object — bindCache - Shiny
To see if the value should be computed, a cached reactive evaluates the key, and then serializes and hashes the result. If the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We are going to change serialization so there is a chance (since you’ve set the issue as low priority) 😉
Not always, but… why not
enum
with values (xyz = 2
,abc = 10
etc)? Value will be compiled asint
so zero impact on performance, and you can also compare them like thisEnum.Value1 < Enum.Value2
if necessary (see SimulationAccuracy).IL code