# Improve performance using the backend

Another approach to improve generation and model transformation performance, is to use the M2T Backend. The M2T Backend is a new execution engine for model to text (M2T) and model to model (M2M) transformations that provides:

- compilation of M2T and M2M languages supported on the backend by providing a middleend that translates the respective language into a Backend abstract syntax tree. This AST is in turn compiled to Java. The compiler is still experimental.
- Backeend interpreted execution of M2T and M2M languages supported on the backend.
- performance improvement employing lazy string concatenation and aggressive caching
- language interoperability, e.g. mix Xpand with Xtend2

The M2T Backend provides a compiler that compiles resources written in Xpand / Xtend / Check and other languages supported on the backend to Java. The backend is used as a common platform just like the JVM is a common platform for multiple languages. Languages supported on the backend are interoperable in same way as languages supported on the JVM are interoperable. This enables you to import templates, extensions and transformations written in other languages than Xpand/Xtend/Check and call functions declared therein, e.g. call an QVT transformation from Xpand. As soon as a middleend for Xtend2 is available, interoperability with old fashioned Xpand/Xtend/Check will be supported.

Beginning with the Eclipse Helios release (Eclipse 3.6) the M2T Backend is part of M2T Xpand. As of the Eclipse Indigo release the Backend Compiler has been added.

## Technical background

The basic idea behind the M2T Backend is to not build a compiler for every language but use an intermediary "language", i.e. the backend abstract syntax tree, that is compiled into executable Java code. Xpand, Xtend and Check are translated into a backend AST by so called middleends . Middleends are specific for each language. Hence, there exists a language specific middleend for each supported language. If a middleend for a certain language is available, it is compilable into Java code and finally to bytecode using a plain Java Compiler or automatically during the build Eclipse JDT Compiler. In contrast to the backend language, Xpand, Xtend and Check are called frontend languages .

The M2T Backend supports functional and aspect oriented programming. Amongst others it supports language features such as:

- closures
- higher order functions - use any expression as parameters, even function calls
- currying of functions
- multi dispatch - call a function based on the runtime parameter types as in Xpand / Xtend / Check instead of the statically assigned parameter types as in Java
- guards on functions - constrain the execution of a function to certain conditions defined in the guard
- deferred evaluation of expressions - use the function call as a placeholder and evaluate the expression later
- AOP
- declare functions in Java using several annotations
- Support for multiple typesystems a.k.a metamodels. Currently JavaBeans, EMF, Eclipse UML2 and XSD are supported.

### How it works in interpreted mode

In interpreted mode the following steps are executed:

- Read a resource, e.g. an Xpand template.
- Find the responsible middleend , that is capable to convert the frontend language AST (e.g. Xpand) into the backend AST . Whether a middleend can handle the transformation of a certain frontend language AST into the backend AST, is determined based on the file ending of the resource, e.g ".xpt" and by trying to parse the resource with the middleends frontend parser.
- Finally, execute the backend AST using the backend.