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.

[CodeGenerator:] Cache static component index lookup into local var

See original GitHub issue

Example:

// Before
public void AddPosition(IntVector2 newValue) {
    var component = CreateComponent<PositionComponent>(CoreComponentsLookup.Position);
    component.value = newValue;
    AddComponent(CoreComponentsLookup.Position, component);
}

// After
public void AddPosition(IntVector2 newValue) {
    var index = CoreComponentsLookup.Position;
    var component = CreateComponent<PositionComponent>(index);
    component.value = newValue;
    AddComponent(index, component);
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Mar 8, 2017

Ooh. Yes I know that. I overlooked the second use of the lookup variable lol. faster by 1 statement. 👍

1reaction
bddckrcommented, Mar 8, 2017

The difference is that the new variable index is used twice. The compiler won’t reuse the same variable for that as it doesn’t know what CoreComponentsLookup.Position does. It could have side effects for example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

map lookups function calls Vs caching the lookup as a ...
I would just retrieve the value from the map directly. Leave it to the calling code to cache the value in a sensible...
Read more >
The Elements of Cache Programming Style
The idea is to modify data structures and code just slightly, trying to use the cache more effectively. Hopefully I will achieve two...
Read more >
Strange caching of Web Page card viewing local static ...
I am using an AppDaemon Python script to create a static web page in /config/www/my_location/index.html . This updates index.html every hour ...
Read more >
Caching — list of Rust libraries/crates ...
Crates to store the results of previous computations in order to reuse the results. ... access to local and remote cargo registry indices....
Read more >
Static Lookup Cache
It queries the cache based on the lookup condition for each row that passes into the transformation. When the lookup condition is true,...
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