top | item 4539983

(no title)

rubashov | 13 years ago

How is your example a language thing? Would a JITed language improve the locality of the m_numLoadedAssets variable? I'm not quite sure I get it.

discuss

order

loup-vaillant|13 years ago

m_numLoadedAssets is a member of some unnamed class the snipet of code is extracted from. When you call the method, it is likely deeper in the stack than any local variable, or even in the heap.

It depends where *this is allocated. In the worst case, it is allocated in main memory while you wanted to stay in the graphic memory, or something.

A naive compiler would then access memory (or the cache) instead of using registers. A Sufficiently Advanced Compiler would guess that calling ++ many times is the same as incrementing in one go, and hoist that out of the loop, but apparently this one is a bit cruder.

Now the same could be said about m_numAssets, but this one isn't written to, so the compiler only have to put a copy in a register, which I guess is a simpler optimization to do.

rubashov|13 years ago

You explain the memory locality issue well but the question is how is the situation better in any other language.

hythloday|13 years ago

Any language that gave you more explicit insight into cache spilling, pipeline stalls, DMA wait etc. would be better. Maybe the solution there is better tools, but if you've ever written a C++ parser you might agree that C++ tooling is a language issue. :-)