-
8 Feb 2012 7:04 AM #1
Ext.forEach
Ext.forEach
I noticed that Ext.each is used very frequently. It's a very convenient and flexible way to iterate, but it is also slow.
I suggest adding this mapping and using Ext.forEach instead of Ext.each.
forEach is faster because it maps (in newer browsers) to native forEach. I checked the Ext code base... in many (if not almost all) places each could be replaced by faster forEach because we don't check the return value of the callback.Code:Ext.forEach = ExtArray.forEach
This shortcut would also save a few bytes because it could replace Ext.Array.forEach in a number of places
-
8 Feb 2012 7:43 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
Ext.each is also slow, executing a function for every array/object iteration ("function iteration") comes at a cost and we are looking at removing it all internally. I have already gone through and done this but it's a massive change that needs to be tested and performance analyzed.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
8 Feb 2012 11:00 AM #3
I found a post that disagrees with this approach...
We really shouldn't put our efforts into doing that kind of micro-optimizations by hand. Instead we should build a JavaScript compiler that would do that kind of transformations for us.
-
8 Feb 2012 12:19 PM #4
Ideally, yes. Practically, not quite there yet! http://triin.net/2011/03/02/Optimizi...h:_Not_so_fast!
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
10 Feb 2012 5:58 AM #5
-
10 Feb 2012 6:59 AM #6Sencha - Community Support Team
- Join Date
- Nov 2008
- Location
- San Diego, Peoples' Republic of California
- Posts
- 2,040
- Vote Rating
- 7
If the 90/10 rule is really true, then 90% of these loops should be Ext.each() for maintainability and readability.
SilkJS - Server Side JavaScript Swiss Army Knife and HTTP Server
Powerful, flexible, advanced charting for ExtJS and Touch: http://zingchart.com
Javascript rocks. Even on the server-side:
ExtJS Forums' Server-Side Javascript Social Group
-
10 Feb 2012 7:05 AM #7
-
10 Feb 2012 7:26 AM #8Sencha - Community Support Team
- Join Date
- Nov 2008
- Location
- San Diego, Peoples' Republic of California
- Posts
- 2,040
- Vote Rating
- 7
I'm not an Ext4 user yet, though I've dabbled a little.
Ideally, a forEach() type function should work on both arrays and objects.
For example:
Code:var a = [ 1,2,3]; forEach(a, function(value, key) { console.log(value); }); // => // 1 // 2 // 3 var o = { foo: 'bar', baz: 'zaz' }; forEach(o, function(value, key) { console.log(key + ' = ' + value); }); // => // foo = bar // baz = zazSilkJS - Server Side JavaScript Swiss Army Knife and HTTP Server
Powerful, flexible, advanced charting for ExtJS and Touch: http://zingchart.com
Javascript rocks. Even on the server-side:
ExtJS Forums' Server-Side Javascript Social Group
-
10 Feb 2012 7:29 AM #9Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
I personally wouldn't use Ext.each... Ext.forEach... store.each...
They all are going to execute a function for every iteration that is unneeded. Why not just do a for loop where possible?Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
10 Feb 2012 7:42 AM #10


Reply With Quote
