473,473 Members | 1,513 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DOM latency

Hi,

I have a problem that seems to be related to DOM latency in executing
instructions. How I see the situation, if one line of code produces a
lot of inner instructions, then the engine is slowly executing them
while allowing the following lines of code to be executed as well.

I had similar problems earlier when I tried to put elements into an
existing container on the page, rendering the new elements on the fly.
I solved the problem by first generating the whole container in memory
and then inserting it into a document subtree. But now I have the same
problem, which can be seen in the following pseudo code:

// GENERATE A BIG OBJECT IN MEMORY
// RESTRUCTURE THE BIG OBJECT BY REARRANGING ITS (BIG) SUBOBJECTS
// USE THE BIG OBJECT IN RENDERING THE PAGE

It seems that restructuring the big object doesn't finish before its
elements are used in the next phase, rendering the page, and what we
get is partially correct data on the page, and partially the data from
previous data order in the object. I tried to prove to myself that
this is what is happening, by making a slight time delay between the
second and the third phase in the above pseudo-code, e.g. 1 sec., and
it seems to be working - all the data on the page is correctly
displayed.

Now my question is: if this is true, and the mechanism works as I
described it, how do I correct the code? I don't think there's some
way of "flushing" the instructions to make sure they're all completely
executed, but maybe there is? Do you have some other way of solving
the problem, or do you have an advice for avoiding it?

Thank you for any answer or idea,

Darko

Feb 26 '07 #1
8 2901
VK
On Feb 26, 7:29 pm, "Darko" <darko.maksimo...@gmail.comwrote:
Hi,

I have a problem that seems to be related to DOM latency in executing
instructions. How I see the situation, if one line of code produces a
lot of inner instructions, then the engine is slowly executing them
while allowing the following lines of code to be executed as well.

I had similar problems earlier when I tried to put elements into an
existing container on the page, rendering the new elements on the fly.
I solved the problem by first generating the whole container in memory
and then inserting it into a document subtree. But now I have the same
problem, which can be seen in the following pseudo code:

// GENERATE A BIG OBJECT IN MEMORY
// RESTRUCTURE THE BIG OBJECT BY REARRANGING ITS (BIG) SUBOBJECTS
// USE THE BIG OBJECT IN RENDERING THE PAGE

It seems that restructuring the big object doesn't finish before its
elements are used in the next phase, rendering the page, and what we
get is partially correct data on the page, and partially the data from
previous data order in the object. I tried to prove to myself that
this is what is happening, by making a slight time delay between the
second and the third phase in the above pseudo-code, e.g. 1 sec., and
it seems to be working - all the data on the page is correctly
displayed.

Now my question is: if this is true, and the mechanism works as I
described it, how do I correct the code? I don't think there's some
way of "flushing" the instructions to make sure they're all completely
executed, but maybe there is? Do you have some other way of solving
the problem, or do you have an advice for avoiding it?

Thank you for any answer or idea,

Darko
Browsers do implement delayed graphics context update. If some method
changed DOM property affecting graphics context, the actual repaint
will be made only after finishing the current execution flaw and
returning to the event waiting mode:

function doSomething() {
document.getElementById('myDiv').style.visibility = 'visible';
// DOM interface value is changed, but graphics context not -
// myDiv remains hidden because the current execution flaw
// so far continues
for (var i=0; i<10000; i++) {
// do something
}
}

doSomething();
// end of the current execution flaw, myDiv becomes visible.
It is annoying that javascript doesn't have repaint() method or
similar. The workaround is to apply DOM changes, then give a micro-
interruption of the flaw then continue.

function doSomething() {
document.getElementById('myDiv').style.visibility = 'visible';
window.setTimeout(doTheRest, 50);
}

You are basically discovered this workaround by yourself - but there
is no need to give such huge delays like 1sec. It is important to
_have_ an interruption - the delay itself has no importance, so
10ms-50ms are the regular values.

Feb 26 '07 #2
On Feb 26, 5:53 pm, "VK" <schools_r...@yahoo.comwrote:
On Feb 26, 7:29 pm, "Darko" <darko.maksimo...@gmail.comwrote:
Hi,
I have a problem that seems to be related to DOM latency in executing
instructions. How I see the situation, if one line of code produces a
lot of inner instructions, then the engine is slowly executing them
while allowing the following lines of code to be executed as well.
I had similar problems earlier when I tried to put elements into an
existing container on the page, rendering the new elements on the fly.
I solved the problem by first generating the whole container in memory
and then inserting it into a document subtree. But now I have the same
problem, which can be seen in the following pseudo code:
// GENERATE A BIG OBJECT IN MEMORY
// RESTRUCTURE THE BIG OBJECT BY REARRANGING ITS (BIG) SUBOBJECTS
// USE THE BIG OBJECT IN RENDERING THE PAGE
It seems that restructuring the big object doesn't finish before its
elements are used in the next phase, rendering the page, and what we
get is partially correct data on the page, and partially the data from
previous data order in the object. I tried to prove to myself that
this is what is happening, by making a slight time delay between the
second and the third phase in the above pseudo-code, e.g. 1 sec., and
it seems to be working - all the data on the page is correctly
displayed.
Now my question is: if this is true, and the mechanism works as I
described it, how do I correct the code? I don't think there's some
way of "flushing" the instructions to make sure they're all completely
executed, but maybe there is? Do you have some other way of solving
the problem, or do you have an advice for avoiding it?
Thank you for any answer or idea,
Darko

Browsers do implement delayed graphics context update. If some method
changed DOM property affecting graphics context, the actual repaint
will be made only after finishing the current execution flaw and
returning to the event waiting mode:

function doSomething() {
document.getElementById('myDiv').style.visibility = 'visible';
// DOM interface value is changed, but graphics context not -
// myDiv remains hidden because the current execution flaw
// so far continues
for (var i=0; i<10000; i++) {
// do something
}

}

doSomething();
// end of the current execution flaw, myDiv becomes visible.

It is annoying that javascript doesn't have repaint() method or
similar. The workaround is to apply DOM changes, then give a micro-
interruption of the flaw then continue.

function doSomething() {
document.getElementById('myDiv').style.visibility = 'visible';
window.setTimeout(doTheRest, 50);

}

You are basically discovered this workaround by yourself - but there
is no need to give such huge delays like 1sec. It is important to
_have_ an interruption - the delay itself has no importance, so
10ms-50ms are the regular values.
Thank you for your reply! But, repainting is not the only problem. As
I've described above, the problem appears even before I put anything
to the screen, i.e. if I fetch information from the object in memory
that hasn't yet been finished rearranging its structure, although the
instructions for restructuring have been given in previous line of
code. Then, just after all of that do I put the (dis-)information to
the screen.

Feb 26 '07 #3
VK
On Feb 26, 8:16 pm, "Darko" <darko.maksimo...@gmail.comwrote:
Thank you for your reply! But, repainting is not the only problem. As
I've described above, the problem appears even before I put anything
to the screen, i.e. if I fetch information from the object in memory
that hasn't yet been finished rearranging its structure, although the
instructions for restructuring have been given in previous line of
code. Then, just after all of that do I put the (dis-)information to
the screen.
In Web applications the term "object" becomes rather ambiguous.
There are javascript objects from native and custom constructors like
Array, Date, Object, MyObject etc.
There are scriptable DOM interfaces exposed by DOM Elements.
There are DOM Tree fragments, nodes and node attributes.

All those are very different. This is why a code fragment or a URL
would be more helpful than an abstract schema. That would let to see
where your rendering problems are residing.
>From what are you saying I guess you are working not with javascript
objects but with virtual DOM elements of a kind:
var myDIV = document.createElement('div');
myDiv.x = y;
..
myDiv.y = z;
...

Anything close to the reality?
MVC pattern over behaviors/bindings is regularly a more convenient
approach but alas still lacking universal support (Safari out, Opera
out).

Feb 26 '07 #4
On Feb 27, 5:57 am, "VK" <schools_r...@yahoo.comwrote:
....]
Anything close to the reality?

MVC pattern over behaviors/bindings is regularly a more convenient
approach but alas still lacking universal support (Safari out, Opera
out).
What? Are you refering to the model-view-controler architectural
pattern? If so, I can't see how it has anything to do wither either
Safari or Opera (or any other browser) in particular.

MVC is not even specific to the web, it was first developed a decade
before the web existed.
--
Rob
Feb 26 '07 #5
VK
MVC pattern over behaviors/bindings is regularly a more convenient
approach but alas still lacking universal support (Safari out, Opera
out).

What? Are you refering to the model-view-controler architectural
pattern? If so, I can't see how it has anything to do wither either
Safari or Opera (or any other browser) in particular.

MVC is not even specific to the web, it was first developed a decade
before the web existed.
MVC pattern *over behaviors/bindings*
Feb 26 '07 #6
On Feb 27, 2:29 am, "Darko" <darko.maksimo...@gmail.comwrote:
Hi,

I have a problem that seems to be related to DOM latency in executing
instructions. How I see the situation, if one line of code produces a
lot of inner instructions, then the engine is slowly executing them
while allowing the following lines of code to be executed as well.

I had similar problems earlier when I tried to put elements into an
existing container on the page, rendering the new elements on the fly.
I solved the problem by first generating the whole container in memory
and then inserting it into a document subtree. But now I have the same
problem, which can be seen in the following pseudo code:

// GENERATE A BIG OBJECT IN MEMORY
// RESTRUCTURE THE BIG OBJECT BY REARRANGING ITS (BIG) SUBOBJECTS
// USE THE BIG OBJECT IN RENDERING THE PAGE
What methods are you using? W3C DOM? innerHTML? Some custom library?

It seems that restructuring the big object doesn't finish before its
elements are used in the next phase, rendering the page, and what we
get is partially correct data on the page, and partially the data from
previous data order in the object. I tried to prove to myself that
this is what is happening, by making a slight time delay between the
second and the third phase in the above pseudo-code, e.g. 1 sec., and
it seems to be working - all the data on the page is correctly
displayed.

Now my question is: if this is true, and the mechanism works as I
described it, how do I correct the code?
Impossible to say without seeing the code - post a link or minimal
example.
--
Rob

Feb 26 '07 #7
On Feb 27, 7:31 am, "VK" <schools_r...@yahoo.comwrote:
MVC pattern over behaviors/bindings is regularly a more convenient
approach but alas still lacking universal support (Safari out, Opera
out).
What? Are you refering to the model-view-controler architectural
pattern? If so, I can't see how it has anything to do wither either
Safari or Opera (or any other browser) in particular.
MVC is not even specific to the web, it was first developed a decade
before the web existed.

MVC pattern *over behaviors/bindings*
The OP didn't mention anything what-so-ever about either "behaviors"
or "bindings" - they are irrelevant. The question seemed to be about
whether DOM objects are created in a separate process, and that
process may not be finished before the original process makes use of
the objects it's creating.

The OP might be using a big string of HTML with innerHTML, or maybe
XHR, both of which *might* give the result described in particular
circumstances - but until the OP explains further, it is impossible to
tell. Rabbiting on about MVC, bindings, behaviours, certain browser
an other things totally unrelated to the question is a pointless waste
of time.
--
Rob

Feb 26 '07 #8
On Feb 27, 12:37 am, "RobG" <r...@iinet.net.auwrote:
On Feb 27, 2:29 am, "Darko" <darko.maksimo...@gmail.comwrote:
Hi,
I have a problem that seems to be related to DOM latency in executing
instructions. How I see the situation, if one line of code produces a
lot of inner instructions, then the engine is slowly executing them
while allowing the following lines of code to be executed as well.
I had similar problems earlier when I tried to put elements into an
existing container on the page, rendering the new elements on the fly.
I solved the problem by first generating the whole container in memory
and then inserting it into a document subtree. But now I have the same
problem, which can be seen in the following pseudo code:
// GENERATE A BIG OBJECT IN MEMORY
// RESTRUCTURE THE BIG OBJECT BY REARRANGING ITS (BIG) SUBOBJECTS
// USE THE BIG OBJECT IN RENDERING THE PAGE

What methods are you using? W3C DOM? innerHTML? Some custom library?
It seems that restructuring the big object doesn't finish before its
elements are used in the next phase, rendering the page, and what we
get is partially correct data on the page, and partially the data from
previous data order in the object. I tried to prove to myself that
this is what is happening, by making a slight time delay between the
second and the third phase in the above pseudo-code, e.g. 1 sec., and
it seems to be working - all the data on the page is correctly
displayed.
Now my question is: if this is true, and the mechanism works as I
described it, how do I correct the code?

Impossible to say without seeing the code - post a link or minimal
example.

--
Rob
Well, if that is going to be helpful, I will describe precisely what I
use, since at the moment my javascript code is many kilobytes heavy,
and I don't think you would be glad to read it. Anyway, I use Ajax to
drag the data from the server. The data is described in XML, so I make
use of the integrated xml-parser in javascript to make a DOM-element
from it. Then I use a set of my classes to generate a tree that
reflects about the same structure as the xml itself, accompanied with
a lot of useful (to me) methods. Now, once I have the tree, I start
generating the HTML by using existing elements in the document, that
serve as templates which I clone when I need it. Once in a while, the
user might be eager to rearrange the objects in the tree, so they're
sorted differently etc. When he decides to do that, I call a
corresponding method that sorts the big object, and then printAll()
object to regenerate the HTML. However, this is where the problem
appears - the sorting seems not to be completely rearranged, and
printing already commences - thus I end with an incorrectly generated
HTML with wrong strings etc.

P.S. The classes I'm talking about here all the time is ordinary
"function ClassName(index) { this.index=index; }
ClassName.prototype.methodName = function() { /* ... */ }" js syntax.

Thank you again for your interest, I haven't succeeded to make it work
yet.

Darko

Feb 27 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Tormod Engebu | last post by:
I'm currently using Jet for an Visual Basic Access application. The application is supposed to delete a row in a table, and afterwards update indexes on the remaining rows in that table, by...
3
by: walker_alone | last post by:
I'm develop a realtime voice record and playback on pc soundcard, I use OSS API to implement it, but have latency about 1 seconds, this was to long for voice, how can I reduce the latency? I reduce...
2
by: Wayne M J | last post by:
I am capturing syslogd traffic from a firewall/router, if I display the results to Console it runs fine and dandy, but the minute I need it to go to a ListBox, DataGrid or even a text box problems...
3
by: cochrane68 | last post by:
I'm developing a web application that will be used at very high latency locations (>400ms). I have a lot of javascript files that I use in the application, and therefore often have large numbers...
3
by: Jeff Jarrell | last post by:
I'd like to create a service-locator\proxy type service that I can use to simulate low bandwith situations and latency issues on the service under test. The request comes from the client, is...
1
nguyenthao
by: nguyenthao | last post by:
Could you please tell me what the factors that determine the network latency are? And what exactly is the measurement of bandwidth. Some say Hertz, others say (giga/mega/kilo...)bit/s. And, in...
4
by: 73k5blazer | last post by:
Hello again all.. We have a giant application from a giant software vendor that has very poor SQL. It's a PLM CAD application, that makes a call to the db for every cad node in the assembly. So...
1
by: aalimbl | last post by:
I want to ask one thing that either wireless medium has high latency or wired medium. Please compare latency (propgation delay) between Fiber and Wireless (WiFi or WimAx) Thanks
2
by: jeff80 | last post by:
Hello, I'm an absolute newbie when it comes to SQL. I was told that SQL server does not function well on a WAN where network latency between, say, the SQL server and a front-end server is...
1
by: hzgt9b | last post by:
Using VS2005, VB.NET, I have a multi-threaded application. In one of my threads I need to read a file as a binary stream. I am able to accomplish this using the following code: 1 Dim BinaryFile...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.