Closed Bug 73993 Opened 23 years ago Closed 7 years ago

Optimize XML Base calculation

Categories

(Core :: XML, defect)

defect
Not set
normal

Tracking

()

RESOLVED WONTFIX
Future

People

(Reporter: hjtoi-bugzilla, Assigned: hjtoi-bugzilla)

References

Details

(Keywords: perf)

There are several parts to optimization in XML Base.

1. The implementation should be sharable between all XML content, like normal
page content, XUL etc.
2. Calculated results should be cached.
3. Calculation must be fast.
4. Memory overhead should be minimized.

Memory overhead can be minimized by caching the calculated values in the
document, because most elements would not have XML Base. The document could hold
a tree of all elements that have XML Base attribute and the calculated value,
and a flags that indicates if a branch is up to date. The up to date flag is set
to dirty if document causes base changes in a branch (there are some
optimization tradeoffs here as well, we could mark only set dirty if XML Base
attributes change and elements with XML Base attributes get added/deleted/moved).

Loading a document we would calculate the bases for elements as we go (this way
it would be rather simple because we have the document base and we would then
just have to nsIURI::Resolve() the new base for each element if there was the
XML Base attribute. This could be avoided in load time if we knew there were no
links and or style rules for the links (by default there are style rules for links).

When somebody asks for an element's base, the element asks the document for the
base, passing the element pointer as argument. The document would consult its
tree of XML Base elements, their values and dirty flags. If the element's
ancesror is not found in the base tree, it would return the document base. If an
ancestor is found, but the branch is dirty, the document would recalculate the
branch bases. It would then get the base for the element in question by getting
the closest ancestor's base from the base tree.

Potential interface additions (the obvious name GetBaseURI cannot be used as it
is already taken up by DOM, it returns the URI as string - the DOM version would
call these function(s) and write the nsIURI into a string):

nsIContent:
  NS_IMETHOD GetBaseURIAsURI(nsIURI **aURI) = 0;

nsIDocument:
  NS_IMETHOD GetBaseURIFor(nsIContent *aContent, nsIURI **aURI) = 0;

Note that because the baseURI from DOM is a node interface, we should put these
interfaces into nsIContent, not just nsIXMLContent (and besides, nsIXMLContent
is being phased out).
Moving to future, adding perf keyword. This bug blocks using XML Base with such
CSS rules as :visited etc. because they have to be extremely fast, added dependency.
Blocks: 54047
Keywords: perf
Target Milestone: --- → Future
XLINK related. Changing QA contact to bsharma@netscape.com
QA Contact: petersen → bsharma
So at this point we actually have GetBaseURL on nsIContent and we use it for
style.  It _could_ use some optimizing, though... Either the idea here or just
storing the base in DOMSlots (and killing it off when SetDocument happens). 
That may be a lot more overhead, though...
Does getbaseuri actually show up in profiles?
No, but that's due to:

1)  The fact that we don't support xml:base on non-XHTML HTML nodes (see
http://lxr.mozilla.org/seamonkey/source/content/html/content/src/nsGenericHTMLElement.cpp#1952)

2)  The fact that GetBaseURI is just all broken in XUL (see
http://lxr.mozilla.org/seamonkey/source/content/xul/content/src/nsXULElement.cpp#2926)

So the only way it could show up in profiles is if someone were to profile a
non-XUL XML page.  Not many of those out there.
QA Contact: bsharma → xml
Depends on: 903372
It's pretty clear at this point that if we put any effort into this we should remove xml:base instead.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.