Codon, a Python-based compiler, allows Python scripts to achieve similar performance levels as the C/C++ programming language. (Image Credit: Cg_prodigy/pixabay)
At some point, new or experienced computer programmers have learned Python and realized that it's quite bulky in terms of memory usage and processing power versus C or C++. Researchers at MIT's Computer Science and Artificial Intelligence Laboratory (CSAIL) developed Codon, a compiler designed to efficiently run Python code — similar to the C++ programming languages.
"Typical speedups over Python are on the order of 10-100x or more on a single thread. Codon's performance is typically on par with (and sometimes better than) that of C/C++. Unlike Python, Codon supports native multithreading, which can lead to speedups many times higher still," according to the repository,
However, apart from its delayed open-source license, Condon doesn't have all the Python language modules integrated into it. Some features, including dynamic type manipulation and runtime reflection, are also excluded. These make code analysis and optimization more challenging. Instead, Codon uses a statically-typing compiler engine, which combines with an optimizable and flexible intermediate representation (IR) for quicker code generation.
The table compares Python (CPython 3), PyPy, Codon, and C++ from numerous benchmarks on Python's pyperformance benchmark suite. The y-axis represents the speed-up over the CPython implementation. (Image Credit: MIT)
MIT originally built Codon as a framework to develop high-performance Python DSLs, a language designed for a specific purpose rather than a general-purpose programming language. Now, Condon expanded into a Python 3-compatible language compiler. Codon "enables the development of DSLs that share Python's syntax and semantics together with added domain-specific features and IR optimizations."
The authors said Python scripts run similarly to C since Codon outputs native machine code without Python runtime overhead. "Unlike other performance-oriented Python implementations (such as PyPy or Numba), Codon is built from the ground up as a standalone system that compiles ahead-of-time to a static executable and is not tied to an existing Python runtime (e.g., CPython or RPython) for execution," according to the paper. "As a result, Codon can achieve better performance and overcome runtime-specific issues such as the global interpreter lock."
The team also suggests that Codor-based DSLs could have applications for data compression, parallel programming, and bioinformatics. In addition, Condor can even boost traditional Python applications. However, those using external libraries like Django or DocUtils must use a CPython bridge, decreasing performance. In fact, a developer says a Fibonacci script ran 70 times faster compared to the CPython version.
"Python is the language of choice for domain experts that are not programming experts. If they write a program that gets popular, and many people start using it and run larger and larger datasets, then the lack of performance of Python becomes a critical barrier to success," says Saman Amarasinghe, MIT professor of electrical engineering and computer science and CSAIL principal investigator. "Instead of needing to rewrite the program using a C-implemented library like NumPy or totally rewrite in a language like C, Codon can use the same Python implementation and give the same performance you'll get by rewriting in C. Thus, I believe Codon is the easiest path forward for successful Python applications that have hit a limit due to lack of performance."
So far, Condor is already being used in various fields, including deep learning, and can be used for app development and testing. The developers plan on implementing additional Python features in Condor within the next few months.
Have a story tip? Message me at: http://twitter.com/Cabe_Atwell