Optimizing Matlab through Just-In-Time Specialization

  • Maxime Chevalier-Boisvert
  • Laurie Hendren
  • Clark Verbrugge
Part of the Lecture Notes in Computer Science book series (LNCS, volume 6011)


Scientists are increasingly using dynamic programming languages like Matlab for prototyping and implementation. Effectively compiling Matlab raises many challenges due to the dynamic and complex nature of Matlab types. This paper presents a new JIT-based approach which specializes and optimizes functions on-the-fly based on the current types of function arguments.

A key component of our approach is a new type inference algorithm which uses the run-time argument types to infer further type and shape information, which in turn provides new optimization opportunities. These techniques are implemented in McVM, our open implementation of a Matlab virtual machine. As this is the first paper reporting on McVM, a brief introduction to McVM is also given.

We have experimented with our implementation and compared it to several other Matlab implementations, including the Mathworks proprietary system, McVM without specialization, the Octave open-source interpreter and the McFor static compiler. The results are quite encouraging and indicate that specialization is an effective optimization—McVM with specialization outperforms Octave by a large margin and also sometimes outperforms the Mathworks implementation.


Virtual Machine Type Object Type Information Type Inference Library Function 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


  1. 1.
    Lattner, C.: LLVM: An infrastructure for multi-stage optimization. Master’s thesis, Comp. Sci. Dept., U. of Illinois at Urbana-Champaign (December 2002)Google Scholar
  2. 2.
    Boehm, H., Spertus, M.: Transparent programmer-directed garbage collection for C++ (2007)Google Scholar
  3. 3.
    Biggar, P., de Vries, E., Gregg, D.: A practical solution for scripting language compilers. In: SAC 2009, pp. 1916–1923. ACM, New York (2009)CrossRefGoogle Scholar
  4. 4.
    Almási, G., Padua, D.: MaJIC: compiling MATLAB for speed and responsiveness. In: PLDI 2002, pp. 294–303. ACM, New York (2002)CrossRefGoogle Scholar
  5. 5.
    Elphick, D., Leuschel, M., Cox, S.: Partial evaluation of MATLAB. In: Pfenning, F., Smaragdakis, Y. (eds.) GPCE 2003. LNCS, vol. 2830, pp. 344–363. Springer, Heidelberg (2003)Google Scholar
  6. 6.
    Derose, L., Rose, L.D., Gallivan, K., Gallivan, K., Gallopoulos, E., Gallopoulos, E., Marsolf, B., Marsolf, B., Padua, D., Padua, D.: FALCON: A MATLAB interactive restructuring compiler. In: Huang, C.-H., Sadayappan, P., Banerjee, U., Gelernter, D., Nicolau, A., Padua, D.A. (eds.) LCPC 1995. LNCS, vol. 1033, pp. 269–288. Springer, Heidelberg (1996)Google Scholar
  7. 7.
    Birkbeck, N., Levesque, J., Amaral, J.N.: A dimension abstraction approach to vectorization in MATLAB. In: CGO 2007, pp. 115–130. IEEE Computer Society, Los Alamitos (2007)Google Scholar
  8. 8.
    Joisha, P.G., Banerjee, P.: A translator system for the MATLAB language: Research articles. Softw. Pract. Exper. 37(5), 535–578 (2007)CrossRefGoogle Scholar
  9. 9.
    Rose, L.D., Padua, D.: A MATLAB to Fortran 90 translator and its effectiveness. In: ICS 1996, pp. 309–316. ACM, New York (1996)CrossRefGoogle Scholar
  10. 10.
    Joisha, P.G., Banerjee, P.: An algebraic array shape inference system for MATLAB®. ACM Trans. Program. Lang. Syst. 28(5), 848–907 (2006)CrossRefGoogle Scholar
  11. 11.
    Haldar, M., Nayak, A., Kanhere, A., Joisha, P., Shenoy, N., Choudhary, A., Banerjee, P.: Match virtual machine: An adaptive runtime system to execute MATLAB in parallel. In: ICPP 2000, pp. 145–152 (2000)Google Scholar
  12. 12.
    Jones, N.D., Gomard, C.K., Sestoft, P.: Partial evaluation and automatic program generation. Prentice-Hall, Inc., Englewood Cliffs (1993)zbMATHGoogle Scholar
  13. 13.
    Cooper, K.D., Hall, M.W., Kennedy, K.: Procedure cloning. Computer Languages, 96–105 (1992)Google Scholar
  14. 14.
    Chauhan, A., McCosh, C., Kennedy, K., Hanson, R.: Automatic type-driven library generation for telescoping languages. In: SC 2003, vol. 1, pp. 58113–695 (1917)Google Scholar
  15. 15.
    Chambers, C., Ungar, D.: Customization: optimizing compiler technology for SELF, a dynamically-typed object-oriented programming language. SIGPLAN Not. 24(7), 146–160 (1989)CrossRefGoogle Scholar
  16. 16.
    Kennedy, A., Syme, D.: Design and implementation of generics for the.NET Common Language Runtime. In: PLDI 2001, pp. 1–12. ACM, New York (2001)CrossRefGoogle Scholar
  17. 17.
    Shankar, A., Sastry, S.S., Bodík, R., Smith, J.E.: Runtime specialization with optimistic heap analysis. SIGPLAN Not. 40(10), 327–343 (2005)CrossRefGoogle Scholar
  18. 18.
    Schultz, U., Consel, C.: Automatic program specialization for Java. ACM Trans. Program. Lang. Syst. 25(4), 452–499 (2003)CrossRefGoogle Scholar
  19. 19.
    Rigo, A.: Representation-based just-in-time specialization and the Psyco prototype for Python. In: PEPM 2004, pp. 15–26. ACM, New York (2004)CrossRefGoogle Scholar
  20. 20.
    Carette, J., Kucera, M.: Partial evaluation of Maple. In: PEPM 2007, pp. 41–50. ACM, New York (2007)CrossRefGoogle Scholar
  21. 21.
    Gal, A., Eich, B., Shaver, M., Anderson, D., Mandelin, D., Haghighat, M.R., Kaplan, B., Hoare, G., Zbarsky, B., Orendorff, J., Ruderman, J., Smith, E.W., Reitmaier, R., Bebenita, M., Chang, M., Franz, M.: Trace-based just-in-time type specialization for dynamic languages. In: PLDI 2009, pp. 465–478. ACM, New York (2009)CrossRefGoogle Scholar
  22. 22.
    Duggan, D., Bent, F.: Explaining type inference. Science of Computer Programming, 37–83 (1996)Google Scholar
  23. 23.
    Bacon, D.F., Sweeney, P.F.: Fast static analysis of C++ virtual function calls. In: OOPSLA 1996, pp. 324–341. ACM, New York (1996)CrossRefGoogle Scholar
  24. 24.
    Tip, F., Palsberg, J.: Scalable propagation-based call graph construction algorithms. In: OOPSLA 2000, pp. 281–293. ACM, New York (2000)CrossRefGoogle Scholar
  25. 25.
    Singer, J.: Sparse bidirectional data flow analysis as a basis for type inference. In: Web proceedings of the Applied Semantics Workshop (2004)Google Scholar
  26. 26.
    Joisha, P.G., Banerjee, P.: Correctly detecting intrinsic type errors in typeless languages such as MATLAB. In: APL 2001, pp. 7–21. ACM, New York (2001)CrossRefGoogle Scholar
  27. 27.
    Furr, M., An, J.h.D., Foster, J.S., Hicks, M.: Static type inference for Ruby. In: SAC 2009, pp. 1859–1866. ACM, New York (2009)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2010

Authors and Affiliations

  • Maxime Chevalier-Boisvert
    • 1
  • Laurie Hendren
    • 1
  • Clark Verbrugge
    • 1
  1. 1.School of Computer ScienceMcGill UniversityMontrealCanada

Personalised recommendations