<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Beware of Getters and Setters</title>
	<atom:link href="http://jacksondunstan.com/articles/433/feed" rel="self" type="application/rss+xml" />
	<link>http://jacksondunstan.com/articles/433</link>
	<description>Mastering AS3</description>
	<lastBuildDate>Tue, 07 Feb 2012 09:30:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: jackson</title>
		<link>http://jacksondunstan.com/articles/433/comment-page-1#comment-1283</link>
		<dc:creator>jackson</dc:creator>
		<pubDate>Wed, 03 Nov 2010 17:25:05 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=433#comment-1283</guid>
		<description>The point of the article is to show that getters and setters are slower than regular field access and are therefore an opportunity for optimization. To the extent that you use getters and setters rather than field access in your application, you&#039;ll slow it down.

For example, if you have 100,000 particles in your scene and you use &lt;code&gt;Sprite&lt;/code&gt;&#039;s &lt;code&gt;get x&lt;/code&gt;, &lt;code&gt;get y&lt;/code&gt;, &lt;code&gt;set x&lt;/code&gt; and &lt;code&gt;set y&lt;/code&gt; once per particle, you&#039;ll make 400,000 getter/setter calls. At an average slowdown of 0.0000257ms per getter call (on the 2.0 Ghz Intel Core 2 Duo in the article) compared to &lt;code&gt;MySprite&lt;/code&gt;, you&#039;d incur a 10.28ms slowdown just in overhead for using getters. If you&#039;re trying to maintain 30 FPS, you&#039;ve spent 30% of your available CPU time just on overhead. At 60 FPS, you&#039;ve used 60%.

If you just use a few hundred getters or setters per frame in your application, you probably don&#039;t need to worry about it.</description>
		<content:encoded><![CDATA[<p>The point of the article is to show that getters and setters are slower than regular field access and are therefore an opportunity for optimization. To the extent that you use getters and setters rather than field access in your application, you&#8217;ll slow it down.</p>
<p>For example, if you have 100,000 particles in your scene and you use <code>Sprite</code>&#8216;s <code>get x</code>, <code>get y</code>, <code>set x</code> and <code>set y</code> once per particle, you&#8217;ll make 400,000 getter/setter calls. At an average slowdown of 0.0000257ms per getter call (on the 2.0 Ghz Intel Core 2 Duo in the article) compared to <code>MySprite</code>, you&#8217;d incur a 10.28ms slowdown just in overhead for using getters. If you&#8217;re trying to maintain 30 FPS, you&#8217;ve spent 30% of your available CPU time just on overhead. At 60 FPS, you&#8217;ve used 60%.</p>
<p>If you just use a few hundred getters or setters per frame in your application, you probably don&#8217;t need to worry about it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Enrique</title>
		<link>http://jacksondunstan.com/articles/433/comment-page-1#comment-1279</link>
		<dc:creator>Enrique</dc:creator>
		<pubDate>Wed, 03 Nov 2010 12:28:35 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=433#comment-1279</guid>
		<description>Are you sure the performance is slower in real applications?
You are testing 10 million (!) of calls.
And the diference is 60[ms] for MyPoint and MySprite.
So calling 1million we are losing only 6ms, calling 100000 less than a 1[ms]... I think is not critical for performance.
Is your application accesing 10millions of getters and setters every frame?</description>
		<content:encoded><![CDATA[<p>Are you sure the performance is slower in real applications?<br />
You are testing 10 million (!) of calls.<br />
And the diference is 60[ms] for MyPoint and MySprite.<br />
So calling 1million we are losing only 6ms, calling 100000 less than a 1[ms]&#8230; I think is not critical for performance.<br />
Is your application accesing 10millions of getters and setters every frame?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: （ZZ）Flash Player 10.1 Performance &#124; 傲天翔 の blog</title>
		<link>http://jacksondunstan.com/articles/433/comment-page-1#comment-903</link>
		<dc:creator>（ZZ）Flash Player 10.1 Performance &#124; 傲天翔 の blog</dc:creator>
		<pubDate>Sun, 10 Oct 2010 10:17:58 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=433#comment-903</guid>
		<description>[...] Original Article [...]</description>
		<content:encoded><![CDATA[<p>[...] Original Article [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jackson</title>
		<link>http://jacksondunstan.com/articles/433/comment-page-1#comment-832</link>
		<dc:creator>jackson</dc:creator>
		<pubDate>Wed, 15 Sep 2010 21:28:39 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=433#comment-832</guid>
		<description>I agree that getters and setters provide a lot of flexibility. This article was mostly written as a caution that some of these frequently-used properties are getters and setters rather than properties. With that knowledge I wanted to show the performance consequences that implies and provide a simple tactic for improving performance for those who want to blend performance with the flexibility of getters and setters.</description>
		<content:encoded><![CDATA[<p>I agree that getters and setters provide a lot of flexibility. This article was mostly written as a caution that some of these frequently-used properties are getters and setters rather than properties. With that knowledge I wanted to show the performance consequences that implies and provide a simple tactic for improving performance for those who want to blend performance with the flexibility of getters and setters.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Henke37</title>
		<link>http://jacksondunstan.com/articles/433/comment-page-1#comment-826</link>
		<dc:creator>Henke37</dc:creator>
		<pubDate>Wed, 15 Sep 2010 17:29:18 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=433#comment-826</guid>
		<description>There is a possible reason why some of them are setters and getters: real properties can&#039;t be overridden. The components in Flash does that as a part of their custom scaling logic.</description>
		<content:encoded><![CDATA[<p>There is a possible reason why some of them are setters and getters: real properties can&#8217;t be overridden. The components in Flash does that as a part of their custom scaling logic.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Germain LECOURTOIS</title>
		<link>http://jacksondunstan.com/articles/433/comment-page-1#comment-398</link>
		<dc:creator>Germain LECOURTOIS</dc:creator>
		<pubDate>Thu, 19 Nov 2009 16:03:25 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=433#comment-398</guid>
		<description>I made a test with 10 000 000 iterations and had a getX() method.
On a simple MyPoint class:
public var _x:Number;
public function getX() : Number { return _x;}
public function get x() : Number { return _x;}

Results :
MyPoint.x: 2185 ms
MyPoint.getX: 2444 ms
MyPoint._x: 638 ms</description>
		<content:encoded><![CDATA[<p>I made a test with 10 000 000 iterations and had a getX() method.<br />
On a simple MyPoint class:<br />
public var _x:Number;<br />
public function getX() : Number { return _x;}<br />
public function get x() : Number { return _x;}</p>
<p>Results :<br />
MyPoint.x: 2185 ms<br />
MyPoint.getX: 2444 ms<br />
MyPoint._x: 638 ms</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jackson</title>
		<link>http://jacksondunstan.com/articles/433/comment-page-1#comment-363</link>
		<dc:creator>jackson</dc:creator>
		<pubDate>Tue, 10 Nov 2009 05:12:47 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=433#comment-363</guid>
		<description>The &lt;tt&gt;MyPoint&lt;/tt&gt; class is the test of getters without using &lt;tt&gt;Sprite&lt;/tt&gt;. I added it because of Keith Peters&#039; comment above.

I&#039;m not sure what you mean by using &lt;tt&gt;Vector&lt;/tt&gt; and &lt;tt&gt;Dictionary&lt;/tt&gt; classes here. How could this be faster than accessing a public variable? Could you provide a brief code example to show the technique? I&#039;d be very interested to see any additional technique for solving the same problem other than what I&#039;ve already discussed in the article.</description>
		<content:encoded><![CDATA[<p>The <tt>MyPoint</tt> class is the test of getters without using <tt>Sprite</tt>. I added it because of Keith Peters&#8217; comment above.</p>
<p>I&#8217;m not sure what you mean by using <tt>Vector</tt> and <tt>Dictionary</tt> classes here. How could this be faster than accessing a public variable? Could you provide a brief code example to show the technique? I&#8217;d be very interested to see any additional technique for solving the same problem other than what I&#8217;ve already discussed in the article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elliot Rock</title>
		<link>http://jacksondunstan.com/articles/433/comment-page-1#comment-362</link>
		<dc:creator>Elliot Rock</dc:creator>
		<pubDate>Tue, 10 Nov 2009 04:59:38 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=433#comment-362</guid>
		<description>Interesting test, it is a pretty self evident when you consider a getter setter does more but both contained public vars and getter/setters aren&#039;t great methods at tracking a large amount of iterations of classes/objects.

Both the Vector and dictionary classes are better at retrieving and storing data like you are doing. 

But that is of course irrelevant to what you where trying to prove here. Good point over all, it would be good to see a raw test without sprites or using the display list.</description>
		<content:encoded><![CDATA[<p>Interesting test, it is a pretty self evident when you consider a getter setter does more but both contained public vars and getter/setters aren&#8217;t great methods at tracking a large amount of iterations of classes/objects.</p>
<p>Both the Vector and dictionary classes are better at retrieving and storing data like you are doing. </p>
<p>But that is of course irrelevant to what you where trying to prove here. Good point over all, it would be good to see a raw test without sprites or using the display list.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jackson</title>
		<link>http://jacksondunstan.com/articles/433/comment-page-1#comment-357</link>
		<dc:creator>jackson</dc:creator>
		<pubDate>Sat, 07 Nov 2009 16:22:24 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=433#comment-357</guid>
		<description>No, &lt;tt&gt;MySprite&lt;/tt&gt; already has public properties I directly access. One can assume the speed would be the same regardless of what the class is named.</description>
		<content:encoded><![CDATA[<p>No, <tt>MySprite</tt> already has public properties I directly access. One can assume the speed would be the same regardless of what the class is named.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derrick Grigg</title>
		<link>http://jacksondunstan.com/articles/433/comment-page-1#comment-356</link>
		<dc:creator>Derrick Grigg</dc:creator>
		<pubDate>Sat, 07 Nov 2009 12:37:54 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=433#comment-356</guid>
		<description>Did you run a test comparing the access of the getter/setter on the MyPoint class vs setting the __x and __y as public and accessing them directly? That would give you a true apples to apples comparison.</description>
		<content:encoded><![CDATA[<p>Did you run a test comparing the access of the getter/setter on the MyPoint class vs setting the __x and __y as public and accessing them directly? That would give you a true apples to apples comparison.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

