Re: [xml] Deep-copy of xsltStylesheetPtr?

On Sat, 18 Sep 2004, Daniel Veillard wrote:
On Fri, Sep 17, 2004 at 04:46:40PM -0700, Rasmus Lerdorf wrote:
Probably a very lame question.  Feel free to RTFM me to the right set of
docs or an example somewhere.

I am looking for a way to get a deep-copy of an xsltStylesheetPtr the same
way I can copy an xmlDocPtr using xmlMemSetup() and xmlCopyDoc().

  Hum, there is no API for this, it was never needed so far.
It may also be a big problem if you try to decouple memory areas, let me
   - we use string interning for document parsing, using a dictionnary
     stored in doc->dict.
   - when compiling a stylesheet we try to use the same set of strings
     so inherit the doc->dict in the style->dict. In general the stylesheet
     and the document(s) it was build from are deeply related. There
     is pointers from the doc compiled elements to the stylesheet and
     from the stylesheet to the doc. The stylesheet doc is modified
     in the process.
Copying the xsltStylesheetPtr would mean duplicating the doc first too.
I think the simplest is to reparse the stylesheet. Honnestly it's usually
a really fast operation, I doubt it would much cheaper to try to rebuild
all the relationship between a copy of the original document and a new
copy of the original stylesheet structure.
Some explanations about the compilation are at

The dictionnary unification is also used for string interning of the
processed document, which allows to use pointer comparison for a lot of
internal operation when  the transformation occurs instead of doing
string content compare.
It seems you are using memory pools (the xmlMemSetup() trick) I think
this makes copy even harder, it becomes impossible to reuse the original
dictionnary and just increment its use count. Seems in such a situation
the best is to copy the initial document and recompile the stylesheet.

A few more details on what I am doing.  By using xmlMemSetup()
and xmlCopyDoc() I am providing a way for PHP users to store an xmlDoc
struct in shared memory to be shared across Apache/PHP processes.  You get
some decent performance gains by only parsing XML files for an application
once instead of doing it on every single request.

Now I am trying to do the same for XSL transforms.  A very common thing
people do is fetch XML from some source and apply a stylesheet.  The
stylesheet rarely changes so I figured having it cached and ready to apply
without having to recompile it from disk on every request would speed
things up.  I obviously have no idea if it would be faster yet, and if you
tell me it wouldn't be I guess I should believe you.  ;)

If the stylesheet compile really is fast then I can just cache the raw
stylesheet document in shared memory as you suggested and recompile it
when I need it.  Is there perhaps some middle stage I could cache though?
Like reduce it to a set of tokens and store those tokens to speed up the
recompile?  Or store any other sort of hint that could in some way speed
up the recompile?


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]