< select> .remove()性能和必要性 [英] <select>.remove() Performance and Necessity

查看:101
本文介绍了< select> .remove()性能和必要性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




在填写选择列表时,我已经阅读了很多关于IE性能主题的copius条目(或者缺少这些条款的b
)。


我不介意插入性能这么多,(我得到100x120byte行

插入/秒高达500,100周/ 6秒到高达3000,这不是很好但是

然后Row Count点击即可让用户看到,他们可以随时点击

取消按钮,总的来说,我很开心),真正令人失望的是

我是可怜的.REMOVE()!


在获取下一个结果集之前我通过循环选项集合调用

remove(1)来清除现有的选项(I

* do *必须这样做,不是吗?)。 (如果我删除了最后一个选项会更快吗?选项[0]是一个

标题。)对于3000行,这需要难以置信的20 +秒:-(这是

听起来是对的吗?


1)是否只有IE在这方面表现不佳?

2)是否有更快捷或更有效的归零方式选择清单?

2a)w3schools ref表示长度。 attribute"返回下拉列表中

选项的数量它没有说设置或返回

2b)法国人(Stephane?)建议我应该将长度

设置为零,但不会这会导致内存泄漏吗?

3)我是否需要创建一个malloc / realloc函数,该函数保留可用选项对象的高水位
标记这个Drop Down并且只有new当超过这个时,还有一些更多的b $ b选项吗? (但是长度总是关闭的)

4)使用表而不是选择列表?

5)使用其他浏览器


干杯理查德马赫


PS。我将.sort(myCompare)从删除/添加更改为仅更改

..TEXT值,它从30secs / 3000行变为~1秒!

解决方案

Richard Maher写道:





我读了很多在填充选择列表时,关于IE性能主题的copius条目(或

缺少它)。


我不介意插入性能所以很多,(我得到100x120byte行

插入/秒高达500,100个/ 6secs高达3000,这不是很好但是

然后行计数是点击即可让用户查看,他们可以随时点击

取消按钮,所以总体来说我很开心),真正令人失望的是

我是可悲的.REMOVE()!



您是在谈论选择元素还是表格?


在获取之前下一个结果集我清除了现有的选项(我不需要这样做,不是我必须这样做吗?)通过循环选项集合调用

remove( 1)。 (如果我删除了最后一个选项会更快吗?选项[0]是一个

标题。)对于3000行,这需要难以置信的20 +秒:-(这是

听起来好吗?



要一次删除所有选项,请设置select元素'

options.length属性为零。


1)是否只有IE在这方面表现不佳?



糟糕的是什么?可能是使用最快且最跨浏览器的方法来创建选项元素:


select.options [i] =新选项(optText,optValue) );


2)是否有更快或更有效的方法将选择列表归零?



将期权集合的长度属性设置为零。


2a) w3schools ref表示长度。 attribute"返回下拉列表中

选项的数量它没有说设置或返回



w3schools是对javascript的正确介绍,但它不是一个

权限,并且有很多错误和不良建议的实例。阅读W3C

规范:


" unsigned long类型长度

"此属性指定长度或大小列表。


< URL:
http://www.w3.org/TR/DOM-Level-2-HTM...ionsCollection >


2b)法国人(Stephane?)建议我将长度

设为零,但不是这样导致内存泄漏?



为什么会导致内存泄漏?


3)我需要吗?创建一个malloc / realloc函数,为此Dropdown保留可用选项对象的高水位标记,并且只保留new标记。当超过这个时,还有一些更多的b $ b选项吗? (但是长度总是关闭的)



虽然我不知道malloc / realloc对你意味着什么,但无论如何,

在javascript中没有这样的等价物。没有特定的

机制来控制内存分配。


4)使用表而不是选择列表?



它们完全不同。


5)使用其他浏览器





-

Rob


你好Rob ,


感谢您的回复。


您在谈论选择元素还是表格?



选择元素。


要一次删除所有选项,请设置选择元素'' s

options.length属性为零。



:::


>

设置选项集合'的长度属性为零。



:::


>

为什么会导致内存泄漏?



为什么在选择列表的

加载期间实例化的所有New Option对象突然消失并释放内存通过

将数组长度设置为零?也许它不是,但空间/元素

下次再次使用?


无论如何,我会带你的(和Stephane的建议并缩小阵列

长度。谢谢。


我想当外科打击被称为

时,remove()方法是什么?


糟糕的是什么?可能是使用最快且最跨浏览器的方法来创建选项元素:


select.options [i] =新选项(optText,optValue) );



是的,这就是我正在做的事情(我必须坚持第二个参数是

x-browser safe)我正在获得我为插入所描述的性能。它b / b
特别是让我感到悲痛的REMOVE表演。


干杯理查德马赫


" RobG" ; < rg *** @ iinet.net.auwrote in message

news:46 *********************** @ per -qv1-newsreader-01.iinet.net.au ...


Richard Maher写道:

$ b $


我已经阅读了很多关于IE性能主题的copius条目



(填充选择列表时,或者


缺少它们。


我不喜欢这么多介意插入性能(我得到100x120byte行

插入/秒高达500,100个/ 6secs高达3000,这不是很好





然后行计数点击即可让用户查看和他们可以点击





" cancel"按钮在任何时候,总的来说我很高兴),真正的



令人失望


我是.REMOVE()的可悲!



您是在谈论选择元素还是表格?


在获取之前下一个结果集我通过循环选项集$



调用


remove(1)。 (如果删除最后一个选项会更快吗?选项[0]





header。)对于3000行,这需要令人难以置信的20 +秒:-(这个

听起来是对的吗?



要一次性删除所有选项,请将select元素的

options.length属性设置为零。


1)只有IE在这方面表现不佳吗?



糟糕的是什么?可能是使用最快且最跨浏览器的方法来创建选项元素:


select.options [i] =新选项(optText,optValue) );


2)是否有更快或更有效的方法将选择列表归零?



将期权集合的长度属性设置为零。


2a) w3schools ref表示长度。 attribute"返回下拉列表中

选项的数量它没有说设置或返回



w3schools是对javascript的正确介绍,但它不是一个

权限,并且有许多错误和不良建议的实例。阅读W3C

规范:


" unsigned long类型长度

"此属性指定长度或大小列表。


< URL:
http://www.w3.org/TR/DOM-Level-2-HTM...ionsCollection >


2b)法国人(Stephane?)建议我应该设置



length


为零,但这不会导致内存泄漏吗?



为什么会导致内存泄漏?


3)我需要吗?创建一个malloc / realloc函数,为此Dropdown保留可用选项对象的高水位标记,并且只保留new标记。一些



更多


期权当'超过了? (但是长度总是关闭的)



虽然我不知道malloc / realloc对你意味着什么,但无论如何,

在javascript中没有这样的等价物。没有特定的

机制来控制内存分配。


4)使用表而不是选择列表?



它们完全不同。


5)使用其他浏览器






-

Rob



嗨再次,


无论如何,我会接受你的(和Stephane'的)建议并缩小数组

长度。谢谢。



好​​的我做到了,我现在更有信心不会有内存泄漏

''因为性能仍然像我明确调用时一样废话

..remove()


如果我目前在selectList中有3000x120byte行,则需要

~24secs在开始重新填充选择列表之前将长度设置为零(或者在我的情况下为one,并使用header

行)下一个结果

设定。 (然后大约1分10秒重新填充它)


有人可以通过合理的方式来管理我的期望吗?性能

应该与选择列表一起?


奇怪的(至少对我来说)是CPU绑定并且不会出现

根本就是内存问题。该页面显示100%cpu,同时取消分配

,然后短暂休息,直到服务器用数据启动套接字和

然后它是100%直到最后一行插入。内存使用情况并没有让人看到预算。 (对于米老鼠的工作来说,这是一个很大的CPU负担我们正在讨论!
谈论!)


这肯定是导航错误吗?是否有一些明显的IE或Windows

调整参数我应该看一下?


再次,我将setTimeout(getNextRecord,0)作为循环控件这样

记录计数点击,屏幕就会更新。但很明显,

不应该影响免费。处理。我会把

的长度设置为零而不是一个,看看是否会产生影响。


干杯理查德马赫


BTW。它是运行Windows2000和IE6的Pentium 1300MHz笔记本电脑

" Richard Maher" < ma ****** @ hotspamnotmail.com写在留言中

news:f0 ********** @ news-01.bur.connect.com.au .. 。


你好Rob,


感谢您的回复。


您在谈论选择元素还是表格?



选择元素。


要一次删除所有选项,请设置选择元素'' s

options.length属性为零。



:::



将选项集合的长度属性设置为零。



:::



为什么会导致内存泄漏?



为什么在选择列表的

加载期间实例化的所有New Option对象突然消失并释放内存



by


将数组长度设置为零?也许它不是,但空间/元素

下次再次使用?


无论如何,我会带你的(和Stephane的建议并缩小阵列

长度。谢谢。


我想当外科打击被称为

时,remove()方法是什么?


糟糕的是什么?可能是使用最快且最跨浏览器的方法来创建选项元素:


select.options [i] =新选项(optText,optValue) );



是的,这就是我正在做的事情(我必须坚持第二个参数是

x-browser safe)我正在获得我为插入所描述的性能。





特别是REMOVE表现给我带来的悲伤。


干杯理查德马赫


" RobG" < rg *** @ iinet.net.auwrote in message

news:46 *********************** @ per -qv1-newsreader-01.iinet.net.au ...


Richard Maher写道:




>

我已经阅读了很多关于IE

主题的copius条目

表现


(或

$ b $填充选择列表时的缺点。

>

我不介意插入性能这么多,(我得到100x120byte行

插入/秒最多500,100个/ 6个最多3000个,这不是



很棒




然后点击行计数离开供用户查看,他们可以



点击




" cancel"按钮在任何时候,总的来说我很高兴),真正的



令人失望


我是.REMOVE()的可悲!



您是在谈论选择元素还是表格?


在获取之前下一个结果集我清除现有选项



(I


* do *必须这样做不是吗?)循环选项集



调用


remove(1)。 (如果我删除最后一个选项会更快吗?



选项[0]




header。)对于3000行,这需要难以置信的20 +秒:-($) b $ b



这个


听起来好吗?



要一次性删除所有选项,请设置选择元素'

options.length属性为零。


1)是否只有IE在这方面表现不佳?



糟糕的是什么?可能是使用最快且最跨浏览器的方法来创建选项元素:


select.options [i] =新选项(optText,optValue) );


2)是否有更快或更有效的方法将Select
归零



列表?



将选项集合的长度属性设置为零。


2a)w3schools ref表示长度。 attribute"返回数字





下拉列表中的选项"它没有说设置或返回



w3schools是对javascript的正确介绍,但它不是一个

权限,并且有很多错误和不良建议的实例。阅读W3C

规范:


" unsigned long类型长度

"此属性指定长度或大小列表。


< URL:
http://www.w3.org/TR/DOM-Level-2-HTM...ionsCollection >


2b)法国人(Stephane?)建议我应该设置



length


为零,但这不会导致内存泄漏吗?



为什么会导致内存泄漏?


3)我需要吗?创建一个malloc / realloc函数,保持



high-water

< blockquote class =post_quotes>


此下拉菜单的可用选项对象标记,仅new



some


more


选项何时超出? (但是长度总是



off)



虽然我不知道malloc / realloc对你意味着什么,但无论如何,

在javascript中没有这样的等价物。没有特定的

机制来控制内存分配。


4)使用表而不是选择列表?



它们完全不同。


5)使用其他浏览器





-

Rob




Hi,

I have read many of the copius entries on the subject of IE performance (or
the lack thereof) when populating Select Lists.

I don''t mind the insert performance so much, (I get 100x120byte rows
inserted/sec up to 500, and 100rows/6secs up to 3000, which isn''t great but
then the Row Count is clicking away for the user to see and they can hit the
"cancel" button at anytime, so overall I''m happy), what really disappoints
me is the woeful of .REMOVE()!

Before fetching the next result-set I clear down the existing options (I
*do* have to do this don''t I?) by looping through option collection calling
remove(1). (Would it be quicker if I removed the last option? Option[0] is a
header.) For 3000 rows this takes an unbelievable 20+secs :-( Does this
sound about right?

1) Is it only IE that performs badly on this?
2) Is there a quicker or more efficient way of zeroing the Select List?
2a) The w3schools ref says the "length" attribute "Returns the number of
options in a dropdown list" it doesn''t say "sets Or returns"
2b) The French guy (Stephane?) suggested that I should just set the length
to zero, but wouldn''t that result in a memory leak?
3) Do I need to create a malloc/realloc function that keeps a high-water
mark of available option objects for this Drop Down and only "new" some more
options when that''s exceeded? (But then the Length would always be off)
4) Use tables and not select lists?
5) Use another browser

Cheers Richard Maher

PS. I changed the .sort(myCompare) from removing/adding to just changing the
..TEXT value and it went from 30secs/3000 rows to ~1sec!

解决方案

Richard Maher wrote:

Hi,

I have read many of the copius entries on the subject of IE performance (or
the lack thereof) when populating Select Lists.

I don''t mind the insert performance so much, (I get 100x120byte rows
inserted/sec up to 500, and 100rows/6secs up to 3000, which isn''t great but
then the Row Count is clicking away for the user to see and they can hit the
"cancel" button at anytime, so overall I''m happy), what really disappoints
me is the woeful of .REMOVE()!

Are you talking about a select element or a table?

Before fetching the next result-set I clear down the existing options (I
*do* have to do this don''t I?) by looping through option collection calling
remove(1). (Would it be quicker if I removed the last option? Option[0] is a
header.) For 3000 rows this takes an unbelievable 20+secs :-( Does this
sound about right?

To remove all the options in one go, set the select element''s
options.length attribute to zero.

1) Is it only IE that performs badly on this?

Badly at what? Probably the fastest and most cross-browser method to
create option elements is to use:

select.options[i] = new Option(optText, optValue);

2) Is there a quicker or more efficient way of zeroing the Select List?

Set the options collection''s length property to zero.

2a) The w3schools ref says the "length" attribute "Returns the number of
options in a dropdown list" it doesn''t say "sets Or returns"

w3schools is an OK introduction to javascript, but it is not an
authority and has many errors and instances of bad advice. Read the W3C
specification:

"length of type unsigned long
"This attribute specifies the length or size of the list."

<URL:
http://www.w3.org/TR/DOM-Level-2-HTM...ionsCollection >

2b) The French guy (Stephane?) suggested that I should just set the length
to zero, but wouldn''t that result in a memory leak?

Why would it result in a memory leak?

3) Do I need to create a malloc/realloc function that keeps a high-water
mark of available option objects for this Drop Down and only "new" some more
options when that''s exceeded? (But then the Length would always be off)

While I don''t know what malloc/realloc means to you, but regardless,
there''s no such equivalent in javascript. There are no specific
mechanisms for controlling memory allocation.

4) Use tables and not select lists?

They are totally different things.

5) Use another browser

?
--
Rob


Hi Rob,

Thanks for the reply.

Are you talking about a select element or a table?

Select Element.

To remove all the options in one go, set the select element''s
options.length attribute to zero.

: : :

>
Set the options collection''s length property to zero.

: : :

>
Why would it result in a memory leak?

Why would all of the New Option objects that were instantiated during the
load of the select list suddenly disappear and have their memory freed up by
setting the array length to zero? Maybe it doesn''t, but the space/elements
get re-used next time round?

Anyway, I''ll take your (and Stephane''s) advice and just shrink the array
length. Thanks.

I guess the remove() method is there for when surgical strikes are called
for?

Badly at what? Probably the fastest and most cross-browser method to
create option elements is to use:

select.options[i] = new Option(optText, optValue);

Yep, that''s what I''m doing (I''ll have to stick in the 2nd parameter to be
x-browser safe) and I''m getting the performance I described for inserts. It
was specifically the REMOVE performance that was giving me grief.

Cheers Richard Maher

"RobG" <rg***@iinet.net.auwrote in message
news:46***********************@per-qv1-newsreader-01.iinet.net.au...

Richard Maher wrote:

Hi,

I have read many of the copius entries on the subject of IE performance

(or

the lack thereof) when populating Select Lists.

I don''t mind the insert performance so much, (I get 100x120byte rows
inserted/sec up to 500, and 100rows/6secs up to 3000, which isn''t great

but

then the Row Count is clicking away for the user to see and they can hit

the

"cancel" button at anytime, so overall I''m happy), what really

disappoints

me is the woeful of .REMOVE()!


Are you talking about a select element or a table?

Before fetching the next result-set I clear down the existing options (I
*do* have to do this don''t I?) by looping through option collection

calling

remove(1). (Would it be quicker if I removed the last option? Option[0]

is a

header.) For 3000 rows this takes an unbelievable 20+secs :-( Does this
sound about right?


To remove all the options in one go, set the select element''s
options.length attribute to zero.

1) Is it only IE that performs badly on this?


Badly at what? Probably the fastest and most cross-browser method to
create option elements is to use:

select.options[i] = new Option(optText, optValue);

2) Is there a quicker or more efficient way of zeroing the Select List?


Set the options collection''s length property to zero.

2a) The w3schools ref says the "length" attribute "Returns the number of
options in a dropdown list" it doesn''t say "sets Or returns"


w3schools is an OK introduction to javascript, but it is not an
authority and has many errors and instances of bad advice. Read the W3C
specification:

"length of type unsigned long
"This attribute specifies the length or size of the list."

<URL:
http://www.w3.org/TR/DOM-Level-2-HTM...ionsCollection >

2b) The French guy (Stephane?) suggested that I should just set the

length

to zero, but wouldn''t that result in a memory leak?


Why would it result in a memory leak?

3) Do I need to create a malloc/realloc function that keeps a high-water
mark of available option objects for this Drop Down and only "new" some

more

options when that''s exceeded? (But then the Length would always be off)


While I don''t know what malloc/realloc means to you, but regardless,
there''s no such equivalent in javascript. There are no specific
mechanisms for controlling memory allocation.

4) Use tables and not select lists?


They are totally different things.

5) Use another browser


?
--
Rob



Hi Again,

Anyway, I''ll take your (and Stephane''s) advice and just shrink the array
length. Thanks.

Ok I did that and I''m now more confident that there won''t be a memory leak
''cos the performance is still as crap as when I was explicitly calling
..remove()

If I currently have 3000x120byte rows in the selectList then it takes
~24secs to set the length to zero (or to "one" in my case with a "header"
row) before it starts re-populating the select list with the next result
set. (And then about 1min10secs to repopulate it)

Can someone manage my expectations here on what "reasonable" performance
should be with Select Lists?

The strange (at least to me) thing is that is CPU bound and doesn''t appear
to be a memory issue at all. The page shows 100% cpu while it''s deallocating
and then a short break until the server has primed the socket with data and
then it''s 100% straight until the last row is inserted. Memory usage doesn''t
seen to budge. (That''s a shit load of CPU for the Mickey Mouse work we''re
talking about!)

This has gotta be pilot error surely? Are there some obvious IE or Windows
tuning parameters that I should look at?

Once again, I am setTimeout(getNextRecord,0) as a loop control so that the
Record Count clicks over and the screen gets updated. But clearly that
shouldn''t effect the "Free" processing. I''ll give it a go at setting the
length to zero instead of one to see if that makes a difference.

Cheers Richard Maher

BTW. It''s a Pentium 1300MHz Laptop running Windows2000 and IE6
"Richard Maher" <ma******@hotspamnotmail.comwrote in message
news:f0**********@news-01.bur.connect.com.au...

Hi Rob,

Thanks for the reply.

Are you talking about a select element or a table?


Select Element.

To remove all the options in one go, set the select element''s
options.length attribute to zero.

: : :


Set the options collection''s length property to zero.

: : :


Why would it result in a memory leak?


Why would all of the New Option objects that were instantiated during the
load of the select list suddenly disappear and have their memory freed up

by

setting the array length to zero? Maybe it doesn''t, but the space/elements
get re-used next time round?

Anyway, I''ll take your (and Stephane''s) advice and just shrink the array
length. Thanks.

I guess the remove() method is there for when surgical strikes are called
for?

Badly at what? Probably the fastest and most cross-browser method to
create option elements is to use:

select.options[i] = new Option(optText, optValue);


Yep, that''s what I''m doing (I''ll have to stick in the 2nd parameter to be
x-browser safe) and I''m getting the performance I described for inserts.

It

was specifically the REMOVE performance that was giving me grief.

Cheers Richard Maher

"RobG" <rg***@iinet.net.auwrote in message
news:46***********************@per-qv1-newsreader-01.iinet.net.au...

Richard Maher wrote:

Hi,
>
I have read many of the copius entries on the subject of IE

performance

(or

the lack thereof) when populating Select Lists.
>
I don''t mind the insert performance so much, (I get 100x120byte rows
inserted/sec up to 500, and 100rows/6secs up to 3000, which isn''t

great

but

then the Row Count is clicking away for the user to see and they can

hit

the

"cancel" button at anytime, so overall I''m happy), what really

disappoints

me is the woeful of .REMOVE()!

Are you talking about a select element or a table?

Before fetching the next result-set I clear down the existing options

(I

*do* have to do this don''t I?) by looping through option collection

calling

remove(1). (Would it be quicker if I removed the last option?

Option[0]

is a

header.) For 3000 rows this takes an unbelievable 20+secs :-( Does

this

sound about right?

To remove all the options in one go, set the select element''s
options.length attribute to zero.

1) Is it only IE that performs badly on this?

Badly at what? Probably the fastest and most cross-browser method to
create option elements is to use:

select.options[i] = new Option(optText, optValue);

2) Is there a quicker or more efficient way of zeroing the Select

List?


Set the options collection''s length property to zero.

2a) The w3schools ref says the "length" attribute "Returns the number

of

options in a dropdown list" it doesn''t say "sets Or returns"

w3schools is an OK introduction to javascript, but it is not an
authority and has many errors and instances of bad advice. Read the W3C
specification:

"length of type unsigned long
"This attribute specifies the length or size of the list."

<URL:
http://www.w3.org/TR/DOM-Level-2-HTM...ionsCollection >

2b) The French guy (Stephane?) suggested that I should just set the

length

to zero, but wouldn''t that result in a memory leak?

Why would it result in a memory leak?

3) Do I need to create a malloc/realloc function that keeps a

high-water

mark of available option objects for this Drop Down and only "new"

some

more

options when that''s exceeded? (But then the Length would always be

off)


While I don''t know what malloc/realloc means to you, but regardless,
there''s no such equivalent in javascript. There are no specific
mechanisms for controlling memory allocation.

4) Use tables and not select lists?

They are totally different things.

5) Use another browser

?
--
Rob




这篇关于&lt; select&gt; .remove()性能和必要性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆