Opened 14 years ago

Closed 13 years ago

#7260 closed Bug (wontfix)

node.js -> getParents performance poor

Reported by: campaign Owned by: Garry Yao
Priority: Normal Milestone:
Component: Performance Version: 3.0
Keywords: Cc:

Description (last modified by Krzysztof Studnik)

	getParents : function( closerFirst )
		{
			var node = this;
			var parents = [];

			do
			{
				parents[  closerFirst ? 'push' : 'unshift' ]( node );
			}
			while ( ( node = node.getParent() ) )

			return parents;
		},

unshift method performance poor

example code

	var t = +new Date,s = []
	for(var i = 0;i<1000;i++){
		s.push(i)
	};
	s.reverse();
	alert(+new Date - t) // 2

	var t = +new Date,s = []
	for(var i = 0;i<1000;i++){
		s.unshift(i)
	};

	alert(+new Date - t) //21

in ie8

Attachments (1)

7260.patch (1.5 KB) - added by Garry Yao 14 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 14 years ago by campaign

Component: GeneralPerformance

comment:2 Changed 14 years ago by Krzysztof Studnik

Description: modified (diff)
Keywords: HasPatch added

Please enclose code into code tags.

comment:3 Changed 14 years ago by Krzysztof Studnik

Keywords: HasPatch? added; HasPatch removed
Version: 3.5.3 (SVN - trunk)3.0

comment:4 Changed 14 years ago by Garry Yao

Owner: set to Garry Yao
Status: newreview

Changed 14 years ago by Garry Yao

Attachment: 7260.patch added

comment:5 Changed 14 years ago by Garry Yao

Performance test result.

comment:6 Changed 14 years ago by Frederico Caldeira Knabben

I've created a performance test that reflects our usage of it a bit better:
http://jsperf.com/array-push-vs-unshift

It shows that we'll have no real benefits on changing our code, but the theory can still be accepted (except for Opera).

comment:7 Changed 13 years ago by Frederico Caldeira Knabben

Keywords: HasPatch? removed
Resolution: wontfix
Status: reviewclosed
Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy