During the last years the use of Geant4  in medical physics is increasing. Today Geant4 offers the advantage of a well-validated set of physics models, a modern software technology and a big flexibility to tailor it to the user specific application. Nevertheless, as a software toolkit, Geant4 requires tailoring of the user application and a certain level of knowledge of the C++ programming language and interfaces that Geant4 provides. In the past, there has been also a lack of optimization studies and specialized techniques tailored for medical applications based on Geant4. GAMOS , the Geant4-based Architecture for Medicine- Oriented Simulations, facilitates the use of Geant4 by providing a simple script language that covers most of the needs of any medical physics simulation. Its modular and flexible design, based on the use of the plug-in technology, as well as a clear documentation and detailed examples, makes it easy to extend the framework to cover any extra need an expert user may have. A substantial effort has also been made to provide a comprehensive set of tools to help the user in the debugging and optimization of an application. We describe in this paper the studies and the techniques implemented in GAMOS aimed to optimize the simulation of a radiotherapy external beam application, including the propagation through the accelerator geometry and the calculation of the dose in voxelized phantoms.