question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cache computed values in `Options.cs`

See original GitHub issue

There’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:open
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
krzychu124commented, Apr 4, 2022

We are going to change serialization so there is a chance (since you’ve set the issue as low priority) 😉

1reaction
krzychu124commented, Apr 4, 2022

Obtaining cached value from field will be faster than function call?

Not always, but… why not enum with values (xyz = 2, abc = 10 etc)? Value will be compiled as int so zero impact on performance, and you can also compare them like this Enum.Value1 < Enum.Value2 if necessary (see SimulationAccuracy).

image

IL code image

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found