IMPROVING PERFORMANCE AND EFFICIENCY OF BACKEND DEVELOPMENT USING PYTHON: ANALYSIS, OPTIMIZATION, AND NEW APPROACHES
IMPROVING PERFORMANCE AND EFFICIENCY OF BACKEND DEVELOPMENT USING PYTHON: ANALYSIS, OPTIMIZATION, AND NEW APPROACHES
Alexander Kochnev
Senior Backend Engineer, Your Next Agency,
United States, San Diego
In the current stage of global digitalization, there is a growing interest in modern technologies. The use of various programming languages has become one of the foundations of software application development. Python programming language remains one of the most popular and in-demand languages in recent years. This is due to its high level of ease of use and efficiency. However, despite all its advantages and extensive community, there are still areas that require significant improvement. The standard Python library experiences certain issues, such as low performance compared to other popular languages like C++ or Java. Given the aforementioned factors, the optimization and exploration of new approaches for organizing backend application development using Python become highly relevant and practically valuable.
The relevance of the research topic is also justified by the increasing demand for backend development among developers and business practitioners. Companies show interest in new technologies and systems with multiple functionalities and scalability prospects. As a result, the requirements for programming languages are rising. When developing large projects, specific issues arise with certain operations, which necessitates taking measures to address the situation and create efficient programming conditions.
The objective of this research is to describe the current state and prospects for optimizing the performance of the Python programming language in the field of backend application development.
The issues of improving the performance of programming languages, particularly Python, remain open questions. Currently, these issues are largely unexplored from a scientific perspective and are predominantly examined within the context of practicality and specific programmer approaches. However, there have been some attempts to systematize the processes of language improvement.
For example, in the research conducted by R.B. Arapetyan, an attempt to enhance the performance of programming languages is described using Java as an example. The author highlights the need to consider language typing, profiling and analysis approaches, operational peculiarities, and other factors. In their study, the authors propose translating dynamic profiling of web applications into an optimized compilation system, enabling faster semantic analysis (execution of application functions). As a result, the authors developed an engine that demonstrated high efficiency, particularly in executing operations based on complex multifunctional applications under certain conditions [3].
In the work by S.V. Kalachin, the general conditions for optimizing software systems and applications are described. The author suggests focusing not only on the code itself but also on its capabilities and functions, which creates opportunities for optimizing algorithmic software and achieving a more efficient implementation of assigned tasks [1]. The author's research sheds light on the differences in approaches to improving the performance of programming languages and the software applications built on them. However, within the scope of this current research, the task at hand is to optimize the Python programming language specifically.А.О.
Matveev, A.V., BystroV, V.I., Bibaev, and N.I. Povarov discuss the possibilities of improving the performance of the Python language from the perspective of its application conditions - by enhancing aspects of working with the code autocompletion mechanism, which is integrated into the programming system. This optimization approach is focused solely on improving the programmer's productivity and does not ultimately affect the language itself. The only exception is related to more accurate code autocompletion and the creation of a more optimized software application structure, which can potentially accelerate performance (improve code efficiency) within a small range [2].
Within the scope of this research, the focus is specifically on optimizing and enhancing the performance of the language itself. In this system, we believe that several basic operations can help achieve the set goals:
Firstly, it involves organizing processes for profiling Python code. Profiling is defined as the process of measuring metrics that determine hardware utilization (memory usage, CPU usage, operation execution speed) to track the dynamics of performance bottlenecks and optimize them.
Optimization can be achieved by utilizing certain tools, such as cProfile and profile, which are built into the Python language library. In the case of cProfile, its application is a consequence of working with multi-threaded programs, allowing for the generation of data (statistics) on the number and duration of function calls for analysis and identification of issues, ultimately leading to directions for optimization. The second tool, profile, is an older version that provides more detailed statistics but introduces some overhead in terms of execution speed [4]. Figure 1 illustrates the conceptual scheme of the code profiling process.
Figure 1. Code profiling
The significance of code profiling should be considered from the perspective of performance optimization. The profiling procedure allows developers to precisely determine how resources are utilized within the code and in which sections. This is especially important in large, multifunctional, and complex projects, where small improvements in specific areas can lead to significant enhancements in overall system performance. According to the Python Developers Survey 2023, approximately 70% of developers use profiling in their daily work [7]. All of this indicates the prospects of such an approach for optimization and performance improvement.
Secondly, the use of JIT (Just-In-Time) compilers. JIT compilation is an approach where code is compiled during runtime, rather than ahead of time. This approach significantly improves performance by optimizing the most frequently used code sections. The main directions of JIT compilation include Ruru and Numba. PyPy is an alternative implementation of Python that incorporates a JIT compiler. PyPy demonstrates higher speed compared to the standard CPython interpreter. The overall efficiency metrics of Ruru are presented in Figure 2:
Figure 2. PyPy speed comparison with Python [6]
The data presented in Figure 2 is further supported by other research or reports, such as the Python Developers Survey 2023, where 60% of developers using PyPy indicated performance improvement as the main reason for transitioning to PyPy. The compilation system operates as follows (Figure 3):
Figure 3. JIT compilation algorithm
Another previously mentioned compiler is Numba, which is focused on working with numerical functions. A study from 2023 demonstrates that using Numba can improve the performance of numerical functions up to 50 times compared to native Python code [5].
Thirdly, parallelization and concurrency. This approach involves creating different conditions (models) for working with the processor, which impacts performance. Depending on the usage scenario, programs, and code characteristics, a suitable parallelization model is chosen, which positively affects performance. Figure 4 presents some of the models of parallelization and concurrency:
Figure 4. Parallelization and Competitiveness in Python Optimization
Referring to Figure 4, it can be observed that the choice of parallelization and concurrency methods directly influences the toolkit for accelerating Python code execution. Each method can be selected depending on the intended scenario and programming task.
Fourthly, the application of new approaches and technologies is relevant. According to the Stack Overflow Developer Survey 2023, approximately 65% of developers use Python 3.8 or newer versions [7]. These versions offer numerous improvements and new features, such as the walrus operator, enhanced type annotations, and other capabilities, which collectively contribute to code optimization. Additionally, notable trends include using Python in conjunction with other languages like Rust or Go to address performance-critical tasks.
Each language is employed for its own programming purposes. For instance, Rust provides high performance and memory safety, making it a prospective choice when combined with Python. In cases where extensive computations and data processing are required, the use of Rust can enhance Python program performance by a factor of 10 to 50, depending on specific parameters.
Go is designed for performance and language-level concurrency. When used together with Python, this language also exhibits competitive results, with performance improvements ranging from 5 to 20 times depending on the conditions and circumstances. Overall, specific metrics are always individual, and it is challenging to identify definitive methods and patterns within this system.
Thus, based on the research conducted on optimization and performance enhancement approaches for the Python programming language, it can be concluded that performance optimization can be a crucial aspect of Python development, particularly for applications with large datasets or high execution speed requirements. Promising methods in this regard include profiling, JIT compilation, parallelization and concurrency, as well as utilizing Python in conjunction with other languages. Although each approach has its own prospects and limitations, considering the task and conditions at hand, they can significantly impact code efficiency and improve program performance.
References:
- Speed PyPy. 2023. Available at: https://speed.pypy.org/
- Survey 2023. 2023. Available at: https://insights.stackoverflow.com/survey/
- Kalachin, S.V. Improving the Performance of Robotic Control Systems for Mobile Agricultural Units // Niva Povolzhiya. 2018. No. 2 (47). pp. 118-122.
- Matveev, A.O., Bystrov, A.V., Bibaev, V.I., Povarov, N.I. Development of Software Tools for Enhancing the Functionality of Code Autocompletion Using Machine Learning Algorithms in an Integrated Development Environment for the Python Language // Vestnik NGU. Series: Information Technologies. 2020. No. 2. pp. 62-75.
- Ayrapetyan, R.B., Gavrin, E.A., Shitov, A.N. A Novel Approach for Enhancing Performance of JavaScript Engine for Web Applications // Modern Information Technologies and IT Education. 2017. No. 1. pp. 217-221.
- Libraries for Profiling Python Code. 2022. Available at: https://www.infoworld.com/article/3600993/9-fine-libraries-for-profiling-python-code.html
- Python Interpreters Benchmarks x64 ArchLinux: AMD® Ryzen 7 4700U. 2023. Available at: https://pybenchmarks.org/u64q/numba.php
- Speed PyPy. 2023. Available at: https://speed.pypy.org/
- Survey 2023. 2023. Available at: https://insights.stackoverflow.com/survey/