Performance issues with the existing coding approach using global :: keyword
I have been asked to refactor a particular module in my application and also to tweak some
performance related issues (if any).
Coming to 开发者_StackOverflow社区the module,there are certain portions where it needs some strings to be
displayed. Also the strings are supplied by a Language assembly(.dll) which is
referred in my project, which basically returns a string from an XML file containing
strings if you pass a keyword.
For ex:
Language.GetStringFromID("TXT_WARNING"); would return something like Warning !!
The original developer has generously used
global :: Language.GetInstance().GetStringFromID("KEYWORD") whenever to fetch a string
Question 1, Is this a good approach ??
I had the second thoughts about this approach, i ran a performance profiler and i see that
everytime when string is requested, it nearly takes 500ms to return the string for the
queried keyword.
Before i conclude that this is indeed the culprit, i need some thoughts from .NET Experts
in StackOverflow
Question 2
Is there any performance hit if we use global :: in general ??
Cheers
- It only should be used to eliminate namespace conflicts.
- No performance hit with using
global::
. It's handled by the compiler. Theres nothing about namespaces at runtime.
The performance hit is inside Language.GetStringFromID
The use of the global
keyword has no implication on performance at all.
The equivalent of global:: is always what is used at the IL level, there is no concept of using a namespace there. In other words it is irrelevant for runtime performance.
精彩评论