[flexcoders] Cast or create local var - which is best \ performant
We are haveing a debate here at work regarding the the most performant \ efficient \ best way of dealing with the casting of objects from one form to another. a) One person thinks that casting the object to the correct type each time it is used is better because casting has a compile time penalty, but at runtime does not incurr a cost. b) The other person would have us believe that the creation of a variable of the correct type and casting the object to it and then using the local variable (thereby eliminating many casts)is better. I side with a) on the basis that the creation of the variable and the garbage collection of it costs more than the casting might. Bearing in mind that either of these methods might be performed in hundreds of places in the application. Is there a difference ? Will any one notice. Is one better ?. Are we being a little to retentive ? thanks BOb -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
Re: [flexcoders] Cast or create local var - which is best \ performant
Depends. Local variables are faster in some casese because it uses optimized registers. Promotion is also something to watch out for regarding ints in loops. If you're really interested, go ask the FLASM guys to update their tool for Flash Player 9, and you can inspect the bytecode to see how much is added by certain casting operations. For something more concerete, look here: http://www.flex.org/ACDS/AS3TuningInsideAVM2JIT.pdf http://www.flex.org/ACDS/GC.swf http://www.flex.org/ACDS/Interpreter.swf http://www.flex.org/ACDS/JITMovie.swf - Original Message - From: bobpardoe1959 [EMAIL PROTECTED] To: flexcoders@yahoogroups.com Sent: Thursday, July 27, 2006 12:29 PM Subject: [flexcoders] Cast or create local var - which is best \ performant We are haveing a debate here at work regarding the the most performant \ efficient \ best way of dealing with the casting of objects from one form to another. a) One person thinks that casting the object to the correct type each time it is used is better because casting has a compile time penalty, but at runtime does not incurr a cost. b) The other person would have us believe that the creation of a variable of the correct type and casting the object to it and then using the local variable (thereby eliminating many casts)is better. I side with a) on the basis that the creation of the variable and the garbage collection of it costs more than the casting might. Bearing in mind that either of these methods might be performed in hundreds of places in the application. Is there a difference ? Will any one notice. Is one better ?. Are we being a little to retentive ? thanks BOb -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
Re: [flexcoders] Cast or create local var - which is best \ performant
I would go for b personally because:it makes for more legible code (IMHO)it means you dont have to type as much (I'm lazy)in AS2, local variables were stored in a register that made access much faster - don't know if this is still the case in AS3 (anyone?) On 7/27/06, bobpardoe1959 [EMAIL PROTECTED] wrote: We are haveing a debate here at work regarding the the most performant \ efficient \ best way of dealing with the casting of objects from one form to another. a) One person thinks that casting the object to the correct type each time it is used is better because casting has a compile time penalty, but at runtime does not incurr a cost. b) The other person would have us believe that the creation of a variable of the correct type and casting the object to it and then using the local variable (thereby eliminating many casts)is better. I side with a) on the basis that the creation of the variable and the garbage collection of it costs more than the casting might. Bearing in mind that either of these methods might be performed in hundreds of places in the application. Is there a difference ? Will any one notice. Is one better ?. Are we being a little to retentive ? thanks BOb __._,_.___ -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com SPONSORED LINKS Web site design development Computer software development Software design and development Macromedia flex Software development best practice YAHOO! GROUPS LINKS Visit your group "flexcoders" on the web. To unsubscribe from this group, send an email to:[EMAIL PROTECTED] Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. __,_._,___
Re: [flexcoders] Cast or create local var - which is best \ performant
I prefer b because it is less code to read and write. Gc is not a problem really, because you are just creating references, not copying objects. If you want hard facts, i'd create a loop with a gazillion object accesses Cheers, Ralf. On 7/27/06, bobpardoe1959 [EMAIL PROTECTED] wrote: We are haveing a debate here at work regarding the the most performant \ efficient \ best way of dealing with the casting of objects from one form to another. a) One person thinks that casting the object to the correct type each time it is used is better because casting has a compile time penalty, but at runtime does not incurr a cost. b) The other person would have us believe that the creation of a variable of the correct type and casting the object to it and then using the local variable (thereby eliminating many casts)is better. I side with a) on the basis that the creation of the variable and the garbage collection of it costs more than the casting might. Bearing in mind that either of these methods might be performed in hundreds of places in the application. Is there a difference ? Will any one notice. Is one better ?. Are we being a little to retentive ? thanks BOb -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links -- Ralf Bokelberg [EMAIL PROTECTED] Flex Flash Consultant based in Cologne/Germany -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
RE: [flexcoders] Cast or create local var - which is best \ performant
Casting involves some runtime code; a cast will throw an RTE if it fails. I'd go with b). - Gordon From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Paul BH Sent: Thursday, July 27, 2006 9:39 AM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Cast or create local var - which is best \ performant I would go for b personally because: it makes for more legible code (IMHO) it means you dont have to type as much (I'm lazy) in AS2, local variables were stored in a register that made access much faster - don't know if this is still the case in AS3 (anyone?) On 7/27/06, bobpardoe1959 [EMAIL PROTECTED]nagel.com wrote: We are haveing a debate here at work regarding the the most performant \ efficient \ best way of dealing with the casting of objects from one form to another. a) One person thinks that casting the object to the correct type each time it is used is better because casting has a compile time penalty, but at runtime does not incurr a cost. b) The other person would have us believe that the creation of a variable of the correct type and casting the object to it and then using the local variable (thereby eliminating many casts)is better. I side with a) on the basis that the creation of the variable and the garbage collection of it costs more than the casting might. Bearing in mind that either of these methods might be performed in hundreds of places in the application. Is there a difference ? Will any one notice. Is one better ?. Are we being a little to retentive ? thanks BOb __._,_.___ -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com SPONSORED LINKS Web site design development Computer software development Software design and development Macromedia flex Software development best practice YAHOO! GROUPS LINKS Visit your group "flexcoders" on the web. To unsubscribe from this group, send an email to:[EMAIL PROTECTED] Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. __,_._,___