Projects‎ > ‎XForms‎ > ‎

Improved XPath Variables

NOTE: This page describes an Orbeon Forms project, not a feature which is currently part of Orbeon Forms.


Current issues:
  • binds: with lots of named binds, e.g. created w/ Form Builder, performance is bad (can be O(n2))
  • XPath expressions receive all variables in scope, even if they don't use all of them


In XFormsModelBinds, say you have 100 binds with names and MIPs, 100 variables are scoped for each MIP. This will cause 1002 creation of variable values, which then have to be set on the XPath expressions, and are also used for the XPath cache key. This is very inefficient.


Optimize XPath cache key

The cache key currently concatenates the list of all variable names, which can be huge and is created every time. This would not be needed as part of the key if the expression knew which variables 

XFormsModelBinds don't recompute list of variables every time

The reason the list is computed more than once for a rebuild at this time is that variables are resolved depending on bind iterations.

In the case where a variable is not within an iteration, there is no need to do this.

In the case there are iterations, the list might be recomputed faster, maybe incrementally.

Use expression analysis to keep list of used variables

Most expressions don't make use of all the variables available in scope. In fact most expressions in Form Runner don't use any variables. Right now, we set all of them in a name -> value map.

During PE static analysis, gather the list of variables actually referenced. [NOTE: Did an experiment 2011-11-03, it's easy.]

Then, at runtime, only retrieve the values of such variables that are in use. This is also what will be used for the list of variables in scope when compiling/evaluating the expression.

This requires

Use deferred variables

XPathCacheStaticContext already supports an "allowAllVariables" option, used during static analysis. It might be possible to use deferred variables all the time, so that we never need to pass variable values to XPath evaluation directly.

Next steps

  • think a bit more about best option to optimized binds
    • look more into how Saxon handles variables
    • in particular, check when Saxon allocates slots (! isGlobal, but in our case when does this happen?)
  • think about XFModelBinds algorithm to improve creation of variables list