[Paper Review] Towards Automated Performance Bug Identification in Python
This paper proposes a machine learning approach to detect performance bugs in Python code early in development using static code attributes. By training models on commit-level metrics like lines changed, file age, and file size, the C4.5 decision tree achieved 96% precision, 85% accuracy, and 73% recall in predicting performance bugs, demonstrating that functional defect prediction techniques can be effectively adapted for non-functional performance issues.
Context: Software performance is a critical non-functional requirement, appearing in many fields such as mission critical applications, financial, and real time systems. In this work we focused on early detection of performance bugs; our software under study was a real time system used in the advertisement/marketing domain. Goal: Find a simple and easy to implement solution, predicting performance bugs. Method: We built several models using four machine learning methods, commonly used for defect prediction: C4.5 Decision Trees, Na\"ıve Bayes, Bayesian Networks, and Logistic Regression. Results: Our empirical results show that a C4.5 model, using lines of code changed, file's age and size as explanatory variables, can be used to predict performance bugs (recall=0.73, accuracy=0.85, and precision=0.96). We show that reducing the number of changes delivered on a commit, can decrease the chance of performance bug injection. Conclusions: We believe that our approach can help practitioners to eliminate performance bugs early in the development cycle. Our results are also of interest to theoreticians, establishing a link between functional bugs and (non-functional) performance bugs, and explicitly showing that attributes used for prediction of functional bugs can be used for prediction of performance bugs.
Motivation & Objective
- To address the challenge of late detection and high fix cost of performance bugs in real-time systems.
- To investigate whether static code analysis and repository metrics can predict performance bugs, similar to functional defect prediction.
- To identify key code attributes that correlate with performance bug injection in Python applications.
- To provide a lightweight, early-warning system for developers to prevent performance regressions during continuous integration.
Proposed method
- Collected 2,800 file commits from a three-year real-time bidding (RTB) system to extract static code and commit-level attributes.
- Categorized attributes into project, activity, and experience groups, including lines changed, file age, file size, and commit frequency.
- Preprocessed data and trained four machine learning models: C4.5 Decision Trees, Naïve Bayes, Bayesian Networks, and Logistic Regression.
- Evaluated model performance using standard metrics: precision, recall, and accuracy, and analyzed feature importance for each model.
- Identified and documented 11 performance optimization patterns in Python, such as avoiding repeated method lookups and using in-place operations.
- Used the patterns to validate model predictions and to guide future static analysis rule development.
Experimental results
Research questions
- RQ1Can static code analysis and repository metrics predict performance bugs in Python applications?
- RQ2Which machine learning models perform best in predicting performance bugs using commit-level attributes?
- RQ3Which code attributes (e.g., lines changed, file age) are most predictive of performance bug injection?
- RQ4Can common performance optimization patterns be automatically detected and used to improve prediction models?
Key findings
- The C4.5 decision tree model achieved the best performance with 96% precision, 85% accuracy, and 73% recall using lines of code changed, file age, and file size as predictors.
- Reducing the number of changes per commit significantly decreases the likelihood of injecting performance bugs.
- The study confirms that attributes used for functional defect prediction—such as code churn and file age—also predict performance bugs, establishing a link between functional and non-functional defect prediction.
- The top-performing model identified that high code churn (many lines changed) is strongly associated with performance bug injection.
- The research identified 11 reusable performance optimization patterns in Python, such as using `map()` instead of loops and caching method lookups, which can be used to guide static analysis.
- The results suggest that performance bug detection can be integrated early in CI/CD pipelines using lightweight, static metrics, reducing the need for expensive runtime profiling.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.