Saxon and GWT

Saxon-CE is built by cross-compiling a Java application into highly-optimized JavaScript; the technology that does this is the Google Web Toolkit (GWT). If you're interested in the internals, this section says a little bit about how this is achieved. If you're not interested, you can safely ignore it.

Saxon-CE 1.1 is built using GWT 2.5. This delivers some useful improvements in performance, especially in the size of the Javascript download.

The Java source code for Saxon-CE is about 62K non-comment lines, compared with around 140K for Saxon-HE and 240K for Saxon-EE. Most of the effort therefore went into deleting code that was dispensible in the browser environment. This includes the XQuery processor, the serializer, APIs such as JAXP, XQJ, and s9api, the TinyTree tree implementation, and many other ancillary features.

It was then necessary to fill the gaps left by GWT's incomplete coverage of the Java class library. For example, this meant porting the regular expression handling in Saxon to use the JavaScript regex library in place of the Java one. A number of other classes used by Saxon are not present in GWT, and had to be emulated. Other changes included loading the code for built-in functions statically rather than by using reflection.

Other measures to reduce the size of the software included extracting the data used by the normalize-unicode() function into a separate data file that is downloaded only when this function is used.

There is a small amount of native Javascript to supplement the code generated by GWT. The GWT DOM library masks some features offered by the native Javascript DOM, for example access to DocumentFragment and DocType nodes, and the ability to enumerate the attributes of an element. As well as filling these gaps, Saxon uses native Javascript methods to support the extension functions that access properties of Javascript objects, the ixsl:eval function to execute arbitrary Javascript, and a method to retrieve XML documents synchronously from the server (GWT is used for asynchronous requests).

The resulting JavaScript is a download of approximately 960Kb, which gives acceptable response time to users with a reasonable modern internet connection. Once downloaded, of course, the code will be held in browser cache. However, when designing a web site, it may be advisable to ensure that users are prepared for a slight delay on their first encounter.

GWT provides the capability to develop applications that are distributed between the client and server. Saxon-CE, however, makes no use of this: all the code is client-side. There is no requirement on the server to do anything more than delivering static HTML and JavaScript content.