File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes effect of many objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "effect of many objects" Watch "effect of many objects" New topic
Author

effect of many objects

simon tiberius
Greenhorn

Joined: Oct 30, 2012
Posts: 29
let's say at first I have a web page. in that page, initially there's only one button. if that button is pressed, a new textbox will appear under that button, pressed again, another textbox appears under the last textbox, and so on.

let's say I've pressed that button a million time (that's a million textboxes), what will the effect (cost) be? will the browser hang? will it become very slow (lagging)? or no effect?
after all, every time the page is refreshed, there will be only one button to generate.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

Why not give it a try and let us know?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
simon tiberius
Greenhorn

Joined: Oct 30, 2012
Posts: 29
^
^
I don't know what's your problem for being sarcastic, but it would be much appreciated if you just refrain yourself from commenting if you're not in the mood to help others. no need to spread your foul mood around. after all this is a forum for developers to learn from more experienced developers. I don't think my question is offensive, just want to know the inner working of the major browsers.

In today's modern browser, it's quite hard notice the difference in speed because they're in the order of millisecond. that's why I'm asking if anyone already had the experience with this issue.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

I have no problem -- what's yours?

It's a completely serious response. It's quite easy to write a script that will generate your millions of DOM elements. My suggestion is to go ahead and write it, and find out for yourself what the effect is.

ShowSomeEffort -- you'll a lot more by doing than by simply having someone else do it for you.
simon tiberius
Greenhorn

Joined: Oct 30, 2012
Posts: 29
your comment sure seemed sarcastic from any perspective, but okay, if you say so.

it's not like I'm trying to ask people to test it for me, I'm just asking if anybody already know the effects and would like to share it with everyone reading this thread. that's all.
okay, so how do I test for memory? as of performance, as I said, how can I test it? can't really see it with naked eyes.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

But you are on the right track. Yes, individual operations are hard to measure because they happen so quickly -- especially in today's highly optimized browser JavaScript engines.

The trick is to repeat an operation many times so that you can measure realistic times and gather information from the results. This, by the way, is covered in Chapter 2 of the JavaScript Ninja book.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

simon tiberius wrote:your comment sure seemed sarcastic from any perspective, but okay, if you say so.

An incorrect assumption on your part. You've been around these forums enough to know now that you'll be urged to show some effort and to dig in to find the answers.
simon tiberius
Greenhorn

Joined: Oct 30, 2012
Posts: 29
^
^
I haven't been around a lot. I stumbled upon this forum when googling and just registered this month. and I had the book, but not anymore. well, technically I never have the book since it's not mine. so, care to share the technique to solve this question?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

I've already given you the technique: you asked what would happen if millions of new elements were added to the DOM. So write a script that does just that. Observe the behavior. Does it bog down? Does it crash the browser? At what count do problems begin to appear? Decrease or increase the number of elements created based upon what you find. Do different browsers handle the situation better or worse?

Harder to measure if you only have access to one system: does the amount of available RAM have an effect on the outcome? What about the processor type? OS?
simon tiberius
Greenhorn

Joined: Oct 30, 2012
Posts: 29
I tried inserting with script, but as I thought, because it's loaded in one go, the browser stopped responding. the element inserted was 50000. so, in the end I couldn't observe anything.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

Bear Bibeault wrote:Decrease or increase the number of elements created based upon what you find.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: effect of many objects