home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 1
Development
General Development (no feature request here!)
Using reflection for GUIControlFactory
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="JoeDalton" data-source="post: 4194" data-attributes="member: 10428"><p>According to <a href="http://www.matshelander.com/Weblog/DisplayLogEntry.aspx?LogEntryID=40" target="_blank">this</a> article using reflection for setting private variables is 40 times slower than using some kind of SetVariable(string variableName, object value) method.</p><p></p><p>I can see a number of reasons why your "reflection-version" performs better, without looking at the code.</p><p></p><p>For example take the following function:</p><p></p><p>bool GetString(ref XmlNode RootNode, string strTag, ref string strStringValue)</p><p>{</p><p> XmlNode node = RootNode.SelectSingleNode(strTag);</p><p> if (node == null) return false;</p><p> if (node.InnerText == null) return false;</p><p> if (node.InnerText == "") return false;</p><p> strStringValue = node.InnerText;</p><p> return true;</p><p>}</p><p></p><p>There is abolutely no reason why the XmlNode should be passed as a ref argument because its instance is not changed in this function. You should only use ref arguments if you want to assign another instance to it in the function like it is the case with the string value.</p><p></p><p>[technical stuff]</p><p>In C# all objects are automatically passed by ref. What is done here is passing a pointer to the pointer of the object instead of passing just a pointer to the object.</p><p></p><p>This gives more work to the CLR, because now it has to check whether the pointer that is passed points to the correct type of object</p><p>[/technical stuff]</p><p></p><p>Second</p><p>a lot of casting is going on in that class this also takes a lot of time.</p><p>For example, instead of this:</p><p>if (strType == "image")</p><p>{</p><p> strTexture = ((GUIImage)reference).FileName;</p><p> dwColorKey = ((GUIImage)reference).ColorKey;</p><p> bAspectRatio =((GUIImage)reference).KeepAspectRatio;</p><p> bFiltered =((GUIImage)reference).Filtering;</p><p> bCentered =((GUIImage)reference).Centered;</p><p>}</p><p></p><p>5 casts!!!</p><p></p><p>one should write this:</p><p>if (strType == "image")</p><p>{</p><p> GUIImage img = (GUIImage)reference;</p><p> strTexture = img.FileName;</p><p> dwColorKey = img.ColorKey;</p><p> bAspectRatio = img.KeepAspectRatio;</p><p> bFiltered = img.Filtering;</p><p> bCentered =img..Centered;</p><p>}</p><p></p><p>1 cast</p><p></p><p></p><p>I guess a lot of performance improvements are possibe in this class...</p><p></p><p></p><p>[/url]</p></blockquote><p></p>
[QUOTE="JoeDalton, post: 4194, member: 10428"] According to [url=http://www.matshelander.com/Weblog/DisplayLogEntry.aspx?LogEntryID=40]this[/url] article using reflection for setting private variables is 40 times slower than using some kind of SetVariable(string variableName, object value) method. I can see a number of reasons why your "reflection-version" performs better, without looking at the code. For example take the following function: bool GetString(ref XmlNode RootNode, string strTag, ref string strStringValue) { XmlNode node = RootNode.SelectSingleNode(strTag); if (node == null) return false; if (node.InnerText == null) return false; if (node.InnerText == "") return false; strStringValue = node.InnerText; return true; } There is abolutely no reason why the XmlNode should be passed as a ref argument because its instance is not changed in this function. You should only use ref arguments if you want to assign another instance to it in the function like it is the case with the string value. [technical stuff] In C# all objects are automatically passed by ref. What is done here is passing a pointer to the pointer of the object instead of passing just a pointer to the object. This gives more work to the CLR, because now it has to check whether the pointer that is passed points to the correct type of object [/technical stuff] Second a lot of casting is going on in that class this also takes a lot of time. For example, instead of this: if (strType == "image") { strTexture = ((GUIImage)reference).FileName; dwColorKey = ((GUIImage)reference).ColorKey; bAspectRatio =((GUIImage)reference).KeepAspectRatio; bFiltered =((GUIImage)reference).Filtering; bCentered =((GUIImage)reference).Centered; } 5 casts!!! one should write this: if (strType == "image") { GUIImage img = (GUIImage)reference; strTexture = img.FileName; dwColorKey = img.ColorKey; bAspectRatio = img.KeepAspectRatio; bFiltered = img.Filtering; bCentered =img..Centered; } 1 cast I guess a lot of performance improvements are possibe in this class... [/url] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 1
Development
General Development (no feature request here!)
Using reflection for GUIControlFactory
Contact us
RSS
Top
Bottom