Neil's Place

May 10, 2003

5:37 AM appendChild

While reworking the semantic web stuff I'm doing to be more interesting, I've noticed that while things are starting to work, is it very slow. Clicking on an actor's name takes almost two seconds before the actor's biography and list of movies they have been in appears.

Half of this slowdown is caused by the DOM appendChild function. So I traced through the code to see why it might be taking a while.

Here is what happens when appendChild is called for a XUL element:

  1. Check the node origin to make sure it can be appended.
  2. Ensure that the node is not an ancestor.
  3. If the node is already is the tree, remove the child first.
  4. Check to ensure that the existing children have been generated already, and build them if not. (Template content for instance)
  5. Append the content to the children array.
  6. Set the parent node.
  7. Inform the XBL system that the document for the elementis changing, if necessary.
  8. Set the document of the node.
  9. Check all attributes and if there are event attributes, hook up each event handler, compiling the script if needed.
  10. Repeat the last three steps recursively for all child nodes of the node being appended.
  11. Check if any DOM mutation listeners have been added to the window and would need to be notified of the appended node.
  12. If there are mutation listeners, fire a mutation event.
  13. Add the element's id to a hash, for later use of getElementById.
  14. If the element has a commandupdater attribute, hook it up.
  15. Check if the element is an observes element, and look up the corresponding broadcaster and hook the observer up to it.
  16. If the element isn't an observer, check for an observes attribute, and hook it up to the broadcaster.
  17. Check if the element is a keyset and hook up a key handler as needed.
  18. Check if the element has a datasources attribute, and if so load the datasource and handle all the template related stuff.
  19. Repeat steps 13-18 recursively for all child nodes.
  20. Check if the parent has an XBL binding.
  21. If so (most XUL elements will), get the insertion points, which may nested deeper in the tree.
  22. Look up the anonymous content for the element.
  23. Loop over the insertion points and find the appropriate one to use.
  24. Add the content at that point.
  25. Notify any document observers that the node had been appended.

Anyway, that might explain some of the delay, just in case you thought it was as simple as adding something to an array.

Comments ( 30 )

May 9, 2003

7:25 AM Interesting XUL things.

You might notice some unusual things about these XUL examples:

  1. <button ref="NC:BookmarksRoot" label="OK"
  2. <button id="NC:HistoryRoot" label="OK" oncommand="alert(this.resource);"/>
  3. <tree id="urn:animals:data" datasources="animals.rdf">

Comments ( 9 )

May 8, 2003

4:01 AM From Hyatt

I plan to implement XBL and the XUL layout primitives in Safari eventually - Dave Hyatt

Comments ( 6 )

May 1, 2003

7:15 PM RPath Lives!


The question is, can you figure out what the expression above does? If so, then RPath passes the Syntax Is Comprehensible Test.

Comments ( 27 )

April 30, 2003

5:19 PM Insanity

This guy must be insane.

Comments ( 5 )

April 29, 2003

4:51 AM Questions Revisited

OK. Now I've fixed the formatting on the examples.

Comments ( 12 )

April 27, 2003

5:09 AM XUL Questions and Examples

A new section has been added to XulPlanet! It contains answers to some common XUL questions, and provides a number of new examples.

I'm hoping others might contribute additional examples.

By the way, we've moved to a new host, so if you see anything broken, let us know. I do want to thank the XML Workshop for hosting us for free all these years. But now that XulPlanet has gotten bigger, it's time to move on.

Comments ( 27 )

April 26, 2003

11:20 PM Scary Monsters

Last night I watched the movie Monsters, Inc. Now I realize why I've never seen any monsters in my closet. I've always had the kind of closet that slides open, yet now I know that monsters can only sneak into rooms via closets with standard doors that open outwards.

I feel a bit safer now.

Comments ( 8 )