# Topic merge

The topic merge feature improves the build speed of DITA files and reduces the possibility of meeting the out of memory exception in the build process. As illustrated in the following figure, when you run the build in previous releases of DITA Open Toolkit, the build speed is slow and you are likely to get out of memory exception.

With this enhanced topic merge feature, you will be less likely to meet the out of memory exception error when you build output through DITA files. The intermediate merged file will keep the structure information in the DITA map, and the structured toc will be reflected in the output.

To know more about this topic feature, you can write a script file first. DITA OT 1.3 offers a module, `TopicMerge`, that helps you implement this feature. You can use this module to generate the merged files. A sample usage of this module is as follows.

sample.xml:

    <project name="sample">
    	<property name="dita.dir" value="${basedir}"/>
    	<import file="${dita.dir}${file.separator}build.xml"/>

    	<target name="premerge">
      		<antcall target="preprocess">
      		<param name="args.input" value="${input}"/>
    		<param name="output.dir" value="${dita.dir}${file.separator}output"/>
    		</antcall>
    	</target>
    	<target name="merge"  description="Merge topics" depends="premerge">
    		<basename property="temp.base" file="${input}" suffix=".ditamap"/>
    		<property name="temp.input" value="${basedir}${file.separator}${dita.temp.dir}${file.separator}${temp.base}"/>
    		<dirname property="temp.dir" file="${temp.input}"/>
    		<pipeline message="topicmerge" module="TopicMerge"
    			inputmap="${temp.dir}${file.separator}${temp.base}.ditamap"
    			extparam="output=${dita.dir}${file.separator}output${file.separator}${temp.base}_merged.xml;
          style=${dita.dir}${file.separator}xsl${file.separator}pretty.xsl" />
    	</target>
    </project>

Then, you need to type `ant -f sample.xml merge -Dinput="C:\DITA-OT1.5.4\test.ditamap`" in the command window.
Note: The path for -Dinput must be an absolute path