<?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>Mon, 14 May 2012 17:02:12 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: 2012提升as3程序性能的十大要点 &#124; Flash开发者大会</title>
		<link>http://jacksondunstan.com/articles/433/comment-page-1#comment-24075</link>
		<dc:creator>2012提升as3程序性能的十大要点 &#124; Flash开发者大会</dc:creator>
		<pubDate>Tue, 06 Mar 2012 09:19:27 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=433#comment-24075</guid>
		<description>[...] 新的一年到来了，是时候为flash的性能制定新的解决方案了。今天的文章收集了我认为可以提升flash程序性能的十大要点。继续往下读吧。 1.使用flash的源生代码代替as3 一般情况下，使用flash player的原生代码做一些大负荷的工作要比使用as3去做好的多。因为和调用flash player api（flash包里面的所有东西）里面的方法相比，在vm（虚拟机）里运行你自己的as3代码势必会带来一些间接成本。不适用这个规则的例外是，api有时会做你不想做的事情，比如分配内存 2.减少内存分配以降低gc 除了你预料到的内存分配，比如通过使用某个新的操作触发某个事件，还有很多隐藏的分配，比如关联的字符串对象、flash player自己创建的对象，如事件。这些分配很慢，使用完了回收他们更慢，所以试着去掉这样的分配。 3.减少对象的数目以降低gc 使用完的对象，flash player的垃圾回器会回收他们的内存来重新使用。不幸的是，这个过程是非常缓慢的而且我们不能控制它什么时候执行。所以，尽量重用已经存在的对象而减少使用new来声明新的对象。对这方面有帮助的一个技术是free lists。 4.不要使用任何动态的东西 这包括动态的函数（如无特征的函数和被声明为局部变量的函数），如Object和MovieClip这样的对象，用”[]“操作符访问字段、无类型的变量。这些都比使用相应的静态量（如正规的函数、非动态类、”.”运算符、有类型的变量）要慢的多。 5.把更多的事情交给gpu 现在在flash里面（fp11）我们除了可以使用cpu外，还可以使用显卡的gpu。二者的组合使用是完成高性能3D图像处理（Stage3D）和高清视频（StageVideo）播放的关键。 6.减少函数的调用 非常不幸的是，函数调用在as3里面是非常慢的。这包括总在使用的getter和setter方法（如调用数组的长度Array.length）。尝试用缓存函数的执行结果来代替多次的函数调用，尤其是用getter的时候。在极个别情况下，手动地把一个小的函数体合并到一个更大的函数里面。 7.使用专用的函数或者类，而不是通用的 Sprite比MovieClip省内存，Shape比Sprite省内存，BitmapData的copyPixels方法比draw方法更快。 8.尽量少的使用静态访问 访问静态变量、常量和函数比访问非静态的要慢很多。尽量使用非静态方案或者把静态访问缓存为非静态变量、常量或者局部的变量、常量。 9.局部变量比字段（原文为文fields，译者认为就是所谓的成员变量）更好 读取类变量和对象变量（又叫字段，成员变量）比访问局部变量要慢地多。如果你频繁的使用某个字段访问，那么最好把它缓存为局部变量。 10.清除无意义的代码 经常见到一些变量被初始化为该类型的默认值，这会减缓对象的创造时间和函数的执行时间。作为一个好的习惯，清除那些无用代码，你的整个程序的性能将会提升。 敬请期待更多关于flash性能要点的文章。   此条目由 Mhycoe 发表在 Actionscript3、程序员修养 分类目录，并贴了 actionscript、性能 标签。将固定链接加入收藏夹。 [...]</description>
		<content:encoded><![CDATA[<p>[...] 新的一年到来了，是时候为flash的性能制定新的解决方案了。今天的文章收集了我认为可以提升flash程序性能的十大要点。继续往下读吧。 1.使用flash的源生代码代替as3 一般情况下，使用flash player的原生代码做一些大负荷的工作要比使用as3去做好的多。因为和调用flash player api（flash包里面的所有东西）里面的方法相比，在vm（虚拟机）里运行你自己的as3代码势必会带来一些间接成本。不适用这个规则的例外是，api有时会做你不想做的事情，比如分配内存 2.减少内存分配以降低gc 除了你预料到的内存分配，比如通过使用某个新的操作触发某个事件，还有很多隐藏的分配，比如关联的字符串对象、flash player自己创建的对象，如事件。这些分配很慢，使用完了回收他们更慢，所以试着去掉这样的分配。 3.减少对象的数目以降低gc 使用完的对象，flash player的垃圾回器会回收他们的内存来重新使用。不幸的是，这个过程是非常缓慢的而且我们不能控制它什么时候执行。所以，尽量重用已经存在的对象而减少使用new来声明新的对象。对这方面有帮助的一个技术是free lists。 4.不要使用任何动态的东西 这包括动态的函数（如无特征的函数和被声明为局部变量的函数），如Object和MovieClip这样的对象，用”[]“操作符访问字段、无类型的变量。这些都比使用相应的静态量（如正规的函数、非动态类、”.”运算符、有类型的变量）要慢的多。 5.把更多的事情交给gpu 现在在flash里面（fp11）我们除了可以使用cpu外，还可以使用显卡的gpu。二者的组合使用是完成高性能3D图像处理（Stage3D）和高清视频（StageVideo）播放的关键。 6.减少函数的调用 非常不幸的是，函数调用在as3里面是非常慢的。这包括总在使用的getter和setter方法（如调用数组的长度Array.length）。尝试用缓存函数的执行结果来代替多次的函数调用，尤其是用getter的时候。在极个别情况下，手动地把一个小的函数体合并到一个更大的函数里面。 7.使用专用的函数或者类，而不是通用的 Sprite比MovieClip省内存，Shape比Sprite省内存，BitmapData的copyPixels方法比draw方法更快。 8.尽量少的使用静态访问 访问静态变量、常量和函数比访问非静态的要慢很多。尽量使用非静态方案或者把静态访问缓存为非静态变量、常量或者局部的变量、常量。 9.局部变量比字段（原文为文fields，译者认为就是所谓的成员变量）更好 读取类变量和对象变量（又叫字段，成员变量）比访问局部变量要慢地多。如果你频繁的使用某个字段访问，那么最好把它缓存为局部变量。 10.清除无意义的代码 经常见到一些变量被初始化为该类型的默认值，这会减缓对象的创造时间和函数的执行时间。作为一个好的习惯，清除那些无用代码，你的整个程序的性能将会提升。 敬请期待更多关于flash性能要点的文章。   此条目由 Mhycoe 发表在 Actionscript3、程序员修养 分类目录，并贴了 actionscript、性能 标签。将固定链接加入收藏夹。 [...]</p>
]]></content:encoded>
	</item>
	<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>
</channel>
</rss>

