# 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:

- a foundation for compilation of M2T and M2M languages supported on the backend
- performance improvement employing lazy string concatenation and aggressive caching
- language interoperability, e.g. mix Xtend with operational QVT

One missing feature in Xpand / Xtend / Check, is to be able to compile Xpand templates and Xtend extensions into Java bytecode to speed up generator runs and hence reduce build time. The M2T Backend provides the foundation for compilation of Xpand / Xtend / Check and other languages by providing a common platform just like the JVM is a common platform for multiple languages. Likewise the backend enables language interoperability. This enables you to import templates, extensions and transformations written in other languages than Xpand/Xtend/Check and call functions declared in therein, e.g. call an QVT transformation from Xpand.

Beginning with the Eclipse Helios release (Eclipse 3.6) the M2T Backend is part of M2T Xpand. Currently the M2T Backend only runs in interpreted mode and includes translation of Xpand, Xtend and Check resources into backend code. However performance improvements can already be expected when working with large models. A compiler that generates optimized Java code will become available soon.

## 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 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 there exists a middleend for a language, it will be compilable into bytecode. 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.